control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/deferred.done.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
2.6 KiB
JSON

{"name":"deferred.done","type":"method","title":"deferred.done()","deprecated":null,"removed":null,"desc":" Add handlers to be called when the Deferred object is resolved. ","categories":["deferred-object","version/1.5"],"entries":[{"return":"Deferred","signatures":{"added":"1.5","argument":[{"desc":"\n A function, or array of functions, that are called when the Deferred is resolved.\n ","name":"doneCallbacks","type":"Function"},{"desc":"\n Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.\n ","name":"doneCallbacks","type":"Function","optional":"true"}]},"examples":[{"desc":"Since the <ahref=\"/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.","code":"\n$.get( \"test.php\" ).done(function() {\n alert( \"$.get succeeded\" );\n});\n"},{"desc":"Resolve a Deferred object when the user clicks a button, triggering a number of callback functions:","code":"\n// 3 functions to call when the Deferred object is resolved\nfunction fn1() {\n $( \"p\" ).append( \" 1 \" );\n}\nfunction fn2() {\n $( \"p\" ).append( \" 2 \" );\n}\nfunction fn3( n ) {\n $( \"p\" ).append( n + \" 3 \" + n );\n}\n\n// Create a deferred object\nvar dfd = $.Deferred();\n\n// Add handlers to be called when dfd is resolved\ndfd\n// .done() can take any number of functions or arrays of functions\n .done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )\n// We can chain done methods, too\n .done(function( n ) {\n $( \"p\" ).append( n + \" we're done.\" );\n });\n\n// Resolve the Deferred object when the button is clicked\n$( \"button\" ).on( \"click\", function() {\n dfd.resolve( \"and\" );\n});\n","html":"\n<button>Go</button>\n<p>Ready...</p>\n"}],"longdesc":"\n <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>\n "}]}