forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeferred.then.xml
57 lines (57 loc) · 2.63 KB
/
deferred.then.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?xml version="1.0"?>
<entry name="deferred.then" type="method" return="Promise">
<title>deferred.then()</title>
<signature>
<added>1.5</added>
<argument name="doneCallbacks" type="Function">
<desc>
A function, or array of functions, called when the Deferred is resolved.
</desc>
</argument>
<argument name="failCallbacks" type="Function">
<desc>
A function, or array of functions, called when the Deferred is rejected.
</desc>
</argument>
</signature>
<signature>
<added>1.7</added>
<argument name="doneCallbacks" type="Function">
<desc>
A function, or array of functions, called when the Deferred is resolved.
</desc>
</argument>
<argument name="failCallbacks" type="Function">
<desc>
A function, or array of functions, called when the Deferred is rejected.
</desc>
</argument>
<argument name="progressCallbacks" type="Function" optional="true">
<desc>
A function, or array of functions, called when the Deferred notifies progress.
</desc>
</argument>
</signature>
<desc> Add handlers to be called when the Deferred object is resolved or rejected. </desc>
<longdesc>
<p>All three arguments (including progressCallbacks, as of jQuery 1.7) can be either a single function or an array of functions. The arguments can also be <code>null</code> if no callback of that type is desired. Alternatively, use <code>.done()</code>, <code>.fail()</code> or <code>.progress()</code> to set only one type of callback. </p>
<p>When the Deferred is resolved, the doneCallbacks are called. If the Deferred is instead rejected, the failCallbacks are called. As of jQuery 1.7, the <code>deferred.notify()</code> or <code>deferred.notifyWith()</code> methods can be called to invoke the progressCallbacks as many times as desired before the Deferred is resolved or rejected.</p>
<p>Callbacks are executed in the order they were added. Since
<code>deferred.then</code> returns a Promise, other methods of the
Promise object can be chained to this one, including additional
<code>.then()</code> methods.
</p>
</longdesc>
<example>
<desc>Since the <a href="/jQuery.get"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can attach handlers using the <code>.then</code> method.</desc>
<code><![CDATA[
$.get("test.php").then(
function(){ alert("$.get succeeded"); },
function(){ alert("$.get failed!"); }
);
]]></code>
</example>
<category slug="deferred-object"/>
<category slug="version/1.5"/>
<category slug="version/1.7"/>
</entry>