jQuery Deferred done() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

deferred.done(doneCallbacks) adds handlers that run when a Deferred is resolved (success). Available since jQuery 1.5. It returns the Deferred so you can chain more methods.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
dfd.done(fn)
dfd.done(fn1, fn2)
dfd.done([fn1, fn2], fn3)

resolve("ok")  → done handlers run with "ok"
reject(...)    → done does NOT run

$.get(url).done(fn)  // jqXHR success
CallWhat it does
Deferred / jqXHRObject that can resolve
doneCallbacksFunction or array of functions
Return valueSame Deferred (chainable)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Get a Deferred (e.g. $.Deferred()) or a jqXHR from $.ajax / $.get.
Step 2Call .done(function (value) { ... }) — pass a function or an array of functions.
Step 3When success happens, call resolve(value) (or let AJAX succeed).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Basic Success Handler

Attach done(), then resolve() with a message.

jQuery
var dfd = $.Deferred();

dfd.done(function (value) {
  console.log("done: " + value);
});

dfd.resolve("Request successful");
// done: Request successful
Try It Yourself

How It Works

  1. Create. $.Deferred() starts in the pending state.
  2. Register. done(fn) queues the success callback.
  3. Resolve. resolve("Request successful") settles as success.

Example 2 — Multiple Handlers

Pass functions or arrays; they run in registration order (per the API docs).

jQuery
var dfd = $.Deferred();
var lines = [];

function fn1() { lines.push("1"); }
function fn2() { lines.push("2"); }
function fn3(n) { lines.push(n + " 3 " + n); }

dfd.done([fn1, fn2], fn3).done(function (n) {
  lines.push(n + " we're done.");
});

dfd.resolve("and");
console.log(lines.join(" "));
// 1 2 and 3 and and we're done.
Try It Yourself

How It Works

  1. Arrays allowed. [fn1, fn2] adds both callbacks in order.
  2. Extra args. fn3 and the chained done also receive "and".
  3. Order. Handlers fire in the order they were added.

Example 3 — Multiple Resolve Arguments

resolve can pass several values; done receives them as separate parameters.

jQuery
var dfd = $.Deferred();

dfd.done(function (status, body, type) {
  console.log(status);  // 200
  console.log(body);    // { ok: true }
  console.log(type);    // application/json
});

dfd.resolve(200, "{ ok: true }", "application/json");
Try It Yourself

How It Works

  1. Multi-arg resolve. jQuery forwards every argument to each done callback.
  2. Parameter list. Match them left-to-right: status, body, type.
  3. Use case. Mimics patterns where status and payload travel together.

Frequently Asked Questions

done() registers one or more callbacks that run when the Deferred is resolved (success). Handlers receive the values passed to resolve() or resolveWith(), in registration order.
done() runs only on resolve. fail() runs only on reject. Pair them (or use then with two callbacks) so you cover both outcomes.
For success only, similar: then(onFulfilled) also runs on resolve. done() is success-only and does not accept a rejection handler. then() can take both fulfilled and rejected callbacks (jQuery 3+).
Yes. Pass functions or arrays of functions. Callbacks run in the order they were added. You can also chain .done().done().
Yes. If the Deferred is already resolved, new done() handlers fire immediately with the resolved values.
Yes. jqXHR objects support .done(), .fail(), and .always() — the classic jQuery success-handler pattern.

Next: deferred.fail() Method

Learn how to attach rejection handlers when a Deferred fails.

deferred.fail() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful