jQuery美元.当总是失败时:什么是$.寻找时决定成败



我需要链接2个帖子的结果,并开始与延迟样本发现:http://api.jquery.com/jQuery.when/

var successFunction = function (event) { alert(event.readyState);  };
var failedFunction = function (event) { alert(event.readyState); };
$.when($.ajax("/page1.php", type: 'POST'), $.ajax("/page2.php", type: 'POST'))
  .then(successFunction , failedFunction );

在我的情况下,failedFunction总是触发,即使事件对象和chrome报告以下属性:

readyState: 4
responseText: "OK"
status: 200
statusText: "OK"

在使用以下形式时结果相同:

$.when( $.ajax("/page1.php", type: 'POST'), $.ajax("/page2.php", type: 'POST'))
   .then(successFunction)
   .fail(failFunction);

$是什么?什么时候判断成功/失败?我怎么得到$。当readyState === 4且status === 200时,何时触发successFunction ?它在寻找我没有从服务器发送的其他东西吗?

jQuery在检查ajax请求是否成功时查找以下状态码

status >= 200 && status < 300 || status === 304   

任何其他的都将被认为是不成功的。

既然你有两个ajax请求,我怀疑其中一个是失败的。

尝试记录响应并查看哪个特定的响应失败。

$.when($.ajax("/page1.php", type: 'POST'), $.ajax("/page2.php", type: 'POST')).done(function(a1,  a2){
    /* arguments are [ "success", statusText, jqXHR ] */
   console.log( a1[2] ); 
   console.log( a2[2] ); 
});

谢谢你的帮助。我添加了一个错误:函数(xhr, ajaxOptions, thrownError)到每个。ajax调用,这给了我更多的细节。两者都返回相同的错误"意外的记号O",因为我返回的是"OK"。一旦我把退货单移走,问题就解决了。我没有机会尝试完成的技术,但我相信这将有助于在未来。

最新更新