// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.getJSON( "example.json", function() {
console.log( "success" );
})
.done(function() { console.log( "second success" ); })
.fail(function() { console.log( "error" ); })
.always(function() { console.log( "complete" ); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function() { console.log( "second complete" ); });
Deprecation Notice
The
jqXHR.success()
,jqXHR.error()
, andjqXHR.complete()
callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, usejqXHR.done()
,jqXHR.fail()
, andjqXHR.always()
instead.