jquery - 返回 jqXHR 对象的新 jQuery.ajax 方式的意义/用途/目的

标签 jquery jquery-1.5

从 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/

相关文章:

javascript - 查找父div下的div元素的数量

jquery - 从 jQuery 1.3.2 升级到 jQuery 1.5(或 1.4)

json - 对于 JSON 请求,jQuery 1.5 AJAX 调用失败并显示 "invalid label"

javascript - jQuery Simple Spy 不再适用于 jQuery 1.5

javascript - .val ("value") 在 jQuery 1.5 中没有按预期工作

javascript - 在 JavaScript 中隐藏哈希位置

javascript - 如何将对象数组返回给php中的ajax调用

jquery - .animate() 行为怪异(重复动画)(jQuery)

php - 通过 $.each 函数迭代 json TypeError