Asynchronous code runs in the background — AJAX calls, timers, animations. jQuery Deferred gives you a structured way to run code when those tasks succeed, fail, or update progress. This hub links to 18 Deferred method tutorials.
01
Deferred()
Create objects
02
done / fail
Success & error
03
always
Cleanup
04
then
Chain steps
05
promise
Read-only view
06
18 guides
Full index
Fundamentals
Introduction
When a task takes time — fetching data, waiting for an animation, reading a file — you cannot block the browser. Instead, you register callbacks that run later. jQuery Deferred is the utility that queues those callbacks and fires them when you call resolve() or reject().
What Is jQuery Deferred?
A Deferred object represents the eventual outcome of an asynchronous operation. It can be pending (still running), resolved (success), or rejected (failure). You attach handlers before settlement, and jQuery runs them in order when the state changes.
💡
Beginner Tip
Think of Deferred like a ticket counter: you line up callbacks (done, fail) first, then the clerk calls resolve or reject when your order is ready.
Key Features
Callback attachment — Register multiple handlers for success, failure, progress, or either outcome.
Promise integration — Expose a read-only promise() so callers cannot accidentally resolve your task.
Chaining — Use then() to pipe results through a pipeline, similar to native Promises.
AJAX built-in — $.ajax() returns a jqXHR that already behaves like a Deferred.
Foundation
📝 Syntax
Create a Deferred, attach handlers, and settle it:
jQuery
const dfd = $.Deferred();
dfd.done(function (data) {
console.log("Success:", data);
}).fail(function (err) {
console.error("Failed:", err);
}).always(function () {
console.log("Cleanup runs either way");
});
// Later, when async work finishes:
dfd.resolve("Hello from Deferred");
Method groups
Group
Examples
Purpose
Factory
$.Deferred()
Create a new Deferred object
Handlers
done(), fail(), always()
Register callbacks
Settlement
resolve(), reject()
Finish the async task
Chaining
then(), catch()
Pipeline transforms and errors
Progress
progress(), notify()
Interim status updates
Status
state(), promise()
Inspect or expose read-only access
Cheat Sheet
⚡ Quick Reference
Goal
Method
Create a Deferred
$.Deferred()
On success
dfd.done(fn)
On failure
dfd.fail(fn)
Cleanup either way
dfd.always(fn)
Chain steps
dfd.then(doneFn, failFn)
Mark success
dfd.resolve(value)
Mark failure
dfd.reject(reason)
Check status (jQuery 3+)
dfd.state() → pending | resolved | rejected
Share read-only access
dfd.promise()
Context
When to Use Deferred
Custom async APIs — Wrap setTimeout, third-party SDKs, or Web APIs in a Deferred your app can consume uniformly.
AJAX requests — Chain .done() / .fail() on $.ajax() without nested callbacks.
Animation sequences — Coordinate code that runs when effects complete or fail.
Module boundaries — Return promise() from a module so internals stay private.
Progress UI — Use notify() and progress() for upload bars or multi-step wizards.
Preview
👀 Deferred Lifecycle
A Deferred moves through three states:
pending → resolve() → resolved → done() + always() run pending → reject() → rejected → fail() + always() run pending → notify() → still pending → progress() runs
Deferred Method Tutorial Index
Search by method name or browse by category. Each tutorial includes syntax, five try-it examples, and FAQs.
Getting Started
4 tutorials
Create Deferreds and attach the core success/failure listeners.
Before: pending
After resolve: resolved
After reject: rejected
How It Works
state() replaces deprecated isResolved() / isRejected() with one clear string. A Deferred can only settle once — subsequent resolve/reject calls are ignored.
Real World
🚀 Use Cases
AJAX requests — Handle server responses and errors without deeply nested callbacks.
Animation sequences — Run the next step when .fadeOut() or custom effects complete.
Complex workflows — Coordinate tasks that depend on other async operations finishing first.
Plugin APIs — Let plugin users attach callbacks while you control when work completes.
Benefits
🌟 Advantages
Cleaner organization — Separate success, failure, and cleanup instead of one giant callback.
Better error handling — Route failures to fail() or catch() consistently.
Promise compatibility — Integrates with jQuery AJAX and patterns familiar from native Promises.
Progress support — Report interim status with notify() — something basic callbacks lack.
Tips
💬 Usage Tips
Register handlers first — Attach done / fail before calling resolve or handlers may miss synchronous settlement.
Return promise() — From public functions, not the raw Deferred.
Prefer state() — Over deprecated status helpers in new code.
Use then() for pipelines — Replace deprecated pipe() in jQuery 3+ projects.
Search this index — Jump to any of 18 method pages above.
Watch Out
⚠️ Common Pitfalls
Double settlement — Only the first resolve or reject counts; later calls are ignored silently.
Leaking the Deferred — Returning the Deferred lets callers resolve your task — use promise().
Mixing paradigms — Native Promises and jQuery Deferred are similar but not identical; test mixed chains carefully.
Deprecated pipe() — Still documented for legacy code; choose then() for new tutorials and projects.
Forgetting always() — UI cleanup belongs in always(), not duplicated in both done and fail.
🧠 How Deferred Works
1
Create
$.Deferred() starts in the pending state with empty callback queues.
Factory
2
Register handlers
done, fail, always, and progress queue callbacks for later.
Listen
3
Settle
resolve or reject locks the state and drains the matching queues.
Settle
=
⚡
Responsive async code
Callbacks run in order, UI stays unblocked, and errors have a clear path.
Compatibility
Browser Support
jQuery Deferred ships with jQuery 1.5+ and is fully supported in jQuery 3.7.x. Methods like state() and catch() align with jQuery 3+. For greenfield projects, also consider native Promise — but Deferred remains essential when using jQuery AJAX and legacy plugins.
✓ jQuery 1.5+
Deferred & Promise API
Available wherever jQuery runs — all modern browsers and IE 9+ with a supported jQuery build. Match your jQuery version to project requirements.
100%With jQuery
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
Deferred methodsUniversal
Bottom line: Safe for jQuery-based apps. Prefer state() and then() in jQuery 3+ code; treat pipe() as legacy.
Wrap Up
🎉 Conclusion
jQuery Deferred is a powerful tool for managing asynchronous tasks — from AJAX to animations to custom APIs. Start with $.Deferred(), done(), and resolve(), then explore chaining and progress as you grow.
Use the searchable index to open all 18 tutorials — each includes try-it labs and FAQs.
A Deferred is a jQuery object that represents an asynchronous task. You register callbacks for success (done), failure (fail), cleanup (always), or progress, then settle it later with resolve() or reject(). It powers $.ajax() and custom async APIs.
A Deferred is read-write — you can resolve, reject, and notify. promise() returns a read-only Promise that consumers can listen to but cannot settle. Share the promise with callers; keep the Deferred private inside your module.
Both work. done() and fail() are explicit and great for beginners. then() chains transforms and errors in one pipeline — similar to native Promises. Prefer then() for multi-step pipelines; use done/fail/always for simple AJAX-style handlers.
In jQuery 3+, call state() — it returns "pending", "resolved", or "rejected". Older isResolved() and isRejected() still work but are deprecated.
Yes. jqXHR objects returned by $.ajax() implement the Deferred interface, so you can chain .done(), .fail(), .always(), and .then() directly on AJAX calls.
Read the overview, try the five examples, then open jQuery.Deferred() or always() from Getting Started. Use the search box to jump to any of the 18 method tutorials.
Did you know?
Every $.ajax() call returns a jqXHR object that is also a Promise-like Deferred. That is why $.get("/api/users").done(render).fail(showError) works without you creating a Deferred manually.