我在jQuery站点上看到了这段代码:
1: var jqxhr = $.ajax( "example.php" )
.done(function() { alert("success"); })
.fail(function() { alert("error"); })
.always(function() { alert("complete"); });
2: // perform other work here ...
// Set another completion function for the request above
3: jqxhr.always(function() { alert("second complete"); });2个问题:
我听说回调函数respectively.
success,error,complete被传输到done,fail,always
所以,如果我想在总是回调中使用jqXHR obj,我怎么知道他从哪里来(error或success)?因为方法签名中的params order是different!
//这是在第3处

//here it is at place 1

3:”中看到的那样)我不明白为什么我会需要它?当我得到节3:时,ajax调用已经完成了,已经完成。在什么情况下,3:部分会生效?
发布于 2011-11-07 08:45:01
complete()不是在请求成功与否重要的地方执行操作,而是执行一般性操作,如清理事物、重新启用禁用按钮等。
但是,您可以检查第一个参数=== jqxhr ($.ajax的返回值)--如果检查为真,则知道存在错误。
https://stackoverflow.com/questions/8033719
复制相似问题