1

我哪里错了?

    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 返回错误或正常(出于测试目的),但我无法让 div #note 显示消息并且 div logo_header 不会隐藏。

有什么资料吗?

4

2 回答 2

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 
于 2013-02-16T17:16:31.063 回答
0

Tx,伙计们会考虑你的建议,但我想我发现了问题。我正在使用带有默认 jquery src 的 twitter bootstrap

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) 返回一个数组。所以我认为我需要改变返回的味精/数据。

于 2013-02-16T17:26:16.620 回答