forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeferred.done.xml
67 lines (64 loc) · 2.74 KB
/
deferred.done.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
58
59
60
61
62
63
64
65
66
67
<?xml version="1.0"?>
<entry name="deferred.done" type="method" return="Deferred">
<title>deferred.done()</title>
<signature>
<added>1.5</added>
<argument name="doneCallbacks" type="Function">
<desc>
A function, or array of functions, that are called when the Deferred is resolved.
</desc>
</argument>
<argument name="doneCallbacks" type="Function" optional="true">
<desc>
Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.
</desc>
</argument>
</signature>
<desc> Add handlers to be called when the Deferred object is resolved. </desc>
<longdesc>
<p>The <code>deferred.done()</code> method accepts one or more arguments, all of which can be either a single function or an array of functions. When the Deferred is resolved, the doneCallbacks are called. Callbacks are executed in the order they were added. Since <code>deferred.done()</code> returns the deferred object, other methods of the deferred object can be chained to this one, including additional <code>.done()</code> methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the <a href="/deferred.resolve/"><code>resolve</code></a> or <a href="/deferred.resolveWith/"><code>resolveWith</code></a> method call in the order they were added. For more information, see the documentation for <a href="/category/deferred-object/">Deferred object</a>.</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 a success callback using the <code>.done()</code> method.</desc>
<code><![CDATA[
$.get("test.php").done(function() {
alert("$.get succeeded");
});
]]></code>
</example>
<example>
<desc>Resolve a Deferred object when the user clicks a button, triggering a number of callback functions:</desc>
<code><![CDATA[
/* 3 functions to call when the Deferred object is resolved */
function fn1() {
$("p").append(" 1 ");
}
function fn2() {
$("p").append(" 2 ");
}
function fn3(n) {
$("p").append(n + " 3 " + n);
}
/* create a deferred object */
var dfd = $.Deferred();
/* add handlers to be called when dfd is resolved */
dfd
/* .done() can take any number of functions or arrays of functions */
.done( [fn1, fn2], fn3, [fn2, fn1] )
/* we can chain done methods, too */
.done(function(n) {
$("p").append(n + " we're done.");
});
/* resolve the Deferred object when the button is clicked */
$("button").bind("click", function() {
dfd.resolve("and");
});
]]></code>
<html><![CDATA[
<button>Go</button>
<p>Ready...</p>
]]></html>
</example>
<category slug="deferred-object"/>
<category slug="version/1.5"/>
</entry>