2013-02-16 33 views
1

我哪裏出錯了?無法獲得簡單的jquery ajaxoncomplete工作?

jQuery(document).ready(function($){ 
    //always focus on input field 
    //$('#documentID').focus(); 
    $("#btnSubmit").on("click", function(){ 
     var docID = $('#documentID').val(); 
     alert("test "+docID); 
     var lookupData = new Array(); 
    $.ajax({ 
      type:"POST", 
      url: "lookup.php", 
      data: {documentID: docID}, 
      dataType: 'text', 
      success: function(msg){ 
alert(msg);//shows Wrong as expected 
      //do stuff after the AJAX calls successfully completes 
      $("#note").ajaxComplete(function(){ 
         if(msg == "Wrong") 
         { 
          result = 'Not so OK'; 
          $('#logo_header').hide();//just to test things 
         } 
         else 
         { 
          result = 'OK lookup'; 
          lookuData = msg;//populate all data 
         } 
         $(this).html(result); 

        });//#end ajaxComplete and populate note 
      }//#end success 

     });//#end AJAX 
    })//#end function 

}); 

而且lookup.php返回錯誤或OK(用於測試目的),但我不能得到DIV #note以顯示消息和DIV logo_header不隱藏。

任何信息?

回答

0

我認爲$("#note")不處理ajax調用,因此它從來沒有達到if (msg == "wrong")聲明。

嘗試刪除$("#note").ajaxComplete

而且有:

success: function(msg){ 
alert(msg);//shows Wrong as expected 
     //do stuff after the AJAX calls successfully completes 
        if(msg == "Wrong") 
        { 
         result = 'Not so OK'; 
         $('#logo_header').hide();//just to test things 
        } 
        else 
        { 
         result = 'OK lookup'; 
         lookuData = msg;//populate all data 
        } 
        $(this).html(result); 

     }//#end 
0

TX,你們會考慮你的建議,但我想我發現了問題。我使用Twitter的引導與默認的jQuery SRC

http://code.jquery.com/jquery.js 

,當我使用這個jQuery源

<script src="./site/wp-includes/js/jquery/jquery.js?ver=1.8.3"></script> 

的ajaxComplete似乎正常工作。

所以我的結論jQuery 1.9.1不支持ajaxComplete vs jQuery 1.8.3嗎?

@Aspiring Aqib,這是一個簡單的測試。下一步是從lookup.php(json)返回一個數組。所以我認爲我需要在msg/data正在返回時做出改變。