{"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 jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the .done() 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\n

Ready...

\n"}],"longdesc":"\n

The deferred.done() 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 deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one, including additional .done() methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the resolve or resolveWith method call in the order they were added. For more information, see the documentation for Deferred object.

\n "}]}