从 jQuery 1.5/1.51 版本开始,我们可以像这样发出 ajax 请求
var jqxhr = $.ajax({ url: "example.php" })
.success(function() { alert("success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
1> 我仍在寻找一些示例/演示/一些信息来了解 jQuery.ajax 的这种做法有什么重要目的,而以前的方法则无法实现
2> 这个 jqXHR 对象有多大用处。
3> 我正在寻找一些实际用途
最佳答案
好吧,jQuery 本身 say :
The $.ajax() function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option. The returned object can generally be discarded, but does provide a lower-level interface for observing and manipulating the request. In particular, calling .abort() on the object will halt the request before it completes.
因此,如果由于某种原因您需要创建自己的 XMLHTTPRequest 对象并将其发送到 $.ajax,这提供了一种在请求后获取该对象的方法。
关于jquery - 返回 jqXHR 对象的新 jQuery.ajax 方式的意义/用途/目的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5160067/