deferred.then(doneFilter [, failFilter] [, progressFilter]) adds handlers for resolve, reject, and progress. Since jQuery 1.8 it returns a new Promise that can transform status and values.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
dfd.then(onDone, onFail, onProgress)
// Filter resolve value
dfd.then(function (v) { return v * 2; })
// Fail only
dfd.then(null, onFail)
// Returns a NEW Promise (chainable)
Call
What it does
doneFilter
Runs on resolve; may transform value
failFilter
Runs on reject; may transform reason
progressFilter
Runs on notify / notifyWith
Return value
New Promise (not the same Deferred)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Start from a Deferred or jqXHR (e.g. $.get).
Step 2
Call .then(doneFilter, failFilter) — pass null to skip a slot.
Step 3
Return a value or another Promise from the filter to feed the next step.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Success and Failure Handlers
Official style: two callbacks like $.get(...).then(ok, err).
jQuery
var dfd = $.Deferred();
dfd.then(
function (msg) {
console.log("success: " + msg);
},
function (err) {
console.log("error: " + err);
}
);
dfd.resolve("ok");
// success: ok
Create a Deferred and a filtered Promise via then.
Filter multiplies the resolved value by 2.
Resolve(5) on the original → filtered Promise gets 10.
Example 3 — Filter a Rejection (Recover)
Pass null for success; in jQuery 3+, returning a value from the fail filter recovers the chain.
jQuery
var defer = $.Deferred();
var filtered = defer.then(null, function (value) {
return value * 3; // recover with a new value
});
filtered.done(function (value) {
console.log("recovered (3*6=) 18: " + value);
});
defer.reject(6);
// recovered (3*6=) 18: 18
Promises/A+ (jQuery 3+) — a returned value fulfills the next Promise.
Frequently Asked Questions
then(doneFilter, failFilter, progressFilter) attaches handlers for resolve, reject, and progress. Since jQuery 1.8 it returns a new Promise that can filter or transform values — replacing the deprecated pipe() method.
done() and fail() only run side effects; their return values are ignored. then() filters the chain: returned values (or promises) flow to the next link, and then() itself returns a new Promise.
Yes. As of jQuery 1.8, then() provides pipe-style filtering. pipe() is deprecated in jQuery 3+ — prefer then() for new code.
A plain value (passed downstream), another Deferred/Promise (the chain waits), or a rejection (throw / rejected promise) to fail the next step.
Yes. Pass null for unused slots, e.g. then(null, failFilter) to only transform rejections.
Since jQuery 3.0, Deferred promises are Promises/A+ compatible for chaining and error bubbling, with jQuery extras like progress still available on Deferreds.