tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

deferred.then()

deferred.then( doneCallbacks, failCallbacks )

Returns: Deferred
Description: Add handlers to be called when the Deferred object is resolved or rejected.

Arguments

deferred.then( doneCallbacks, failCallbacks )

version added: 1.5
doneCallbacks
A function, or array of functions, called when the Deferred is resolved.
failCallbacks
A function, or array of functions, that are called when the Deferred is rejected.
Both arguments can be either a single function or an array of functions. Either argument can also be null if no callback of that type is desired. Alternatively, use .done() or .fail() to set only doneCallbacks or failCallbacks. When the Deferred is resolved, the doneCallbacks are called. If the Deferred is instead rejected, the failCallbacks are called. Callbacks are executed in the order they were added. Since deferred.then returns the deferred object, other methods of the deferred object can be chained to this one, including additional .then() methods. For more information, see the documentation for Deferred object.

Example

Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach handlers using the .then method.
$.get("test.php").then(
    function(){ alert("$.get succeeded"); },
    function(){ alert("$.get failed!"); }
);
Was this information helpful?
   

Comments