Deferred Object
As of jQuery 1.5, the Deferred object provides a way to register multiple callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure state of any synchronous or asynchronous function.
Deferred Methods:
Deferred In Action:个
$.get("test.php").done(
function(){ alert("$.get succeeded"); }
);
$.get("test.php")
.done(function(){ alert("$.get succeeded"); })
.fail(function(){ alert("$.get failed!"); });
And it seems that the existing ajax() method callbacks can be chained rather than declared in the settings:
var jqxhr = $.ajax({ url: "example.php" })
.success(function() { alert("success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
Working Example From Eric Hynds blog post: http://jsfiddle.net/ehynds/Mrqf8/
jqXHR
As of jQuery 1.5, the $.ajax() method returns the jXHR object, which is a superset of the XMLHTTPRequest object. For more information, see thejXHR section of the $.ajax entry
From JQUERY 1.5 RELEASED:
DEFERRED OBJECTS
随着Ajax的重写
Additionally you can make your own deferred objects using the exposed jQuery.Deferred. More information about this API can be found in the Deferred Object documentation.
Eric Hynds has written up a good tutorial on Using Deferreds in jQuery 1.5.