forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeferred.always.xml
32 lines (32 loc) · 2.55 KB
/
deferred.always.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0"?>
<entry name="deferred.always" type="method" return="Deferred">
<title>deferred.always()</title>
<signature>
<added>1.6</added>
<argument name="alwaysCallbacks" type="Function">
<desc>
A function, or array of functions, that is called when the Deferred is resolved or rejected.
</desc>
</argument>
<argument name="alwaysCallbacks" type="Function" optional="true">
<desc>
Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected.
</desc>
</argument>
</signature>
<desc> Add handlers to be called when the Deferred object is either resolved or rejected. </desc>
<longdesc>
<p>The argument can be either a single function or an array of functions. When the Deferred is resolved or rejected, the <code>alwaysCallbacks</code> are called. Since <code>deferred.always()</code> returns the Deferred object, other methods of the Deferred object can be chained to this one, including additional <code>.always()</code> methods. When the Deferred is resolved or rejected, callbacks are executed in the order they were added, using the arguments provided to the <a href="/deferred.resolve/"><code>resolve</code></a>, <a href="/deferred.reject/"><code>reject</code></a>, <a href="/deferred.resolveWith/"><code>resolveWith</code></a> or <a href="/deferred.rejectWith/"><code>rejectWith</code></a> method calls. For more information, see the documentation for <a href="/category/deferred-object/">Deferred object</a>.</p>
<p><strong>Note:</strong> The <code>deferred.always()</code> method receives the arguments that were used to <code>.resolve()</code> or <code>.reject()</code> the <code>Deferred</code> object, which are often very different. For this reason, it's best to use it only for actions that do not require inspecting the arguments. In all other cases, use explicit <a href="/deferred.done/"><code>.done()</code></a> or <a href="/deferred.fail/"><code>.fail()</code></a> handlers since the arguments will have well-known orders.</p>
</longdesc>
<example>
<desc>Since the <a href="/jQuery.get/"><code>jQuery.get()</code></a> method returns a <code>jqXHR</code> object, which is derived from a Deferred object, we can attach a callback for both success and error using the <code>deferred.always()</code> method.</desc>
<code><![CDATA[
$.get( "test.php" ).always(function() {
alert( "$.get completed with success or error callback arguments" );
});
]]></code>
</example>
<category slug="deferred-object"/>
<category slug="version/1.6"/>
</entry>