deferred.fail(failCallbacks) adds handlers that run when a Deferred is rejected (failure). Available since jQuery 1.5. It returns the Deferred so you can chain more methods.
Remember
dfd.fail(fn)
dfd.fail(fn1, fn2)
dfd.fail([fn1, fn2], fn3)
reject("err") → fail handlers run with "err"
resolve(...) → fail does NOT run
$.get(url).fail(fn) // jqXHR error
Create or receive a Deferred/Promise, attach fail, then reject (or wait for AJAX to fail).
Get a Deferred (e.g. $.Deferred()) or a jqXHR from $.ajax / $.get.
Call .fail(function (reason) { ... }) — pass a function or an array of functions.
When failure happens, call reject(reason) (or let AJAX fail).
Handlers run in order with the reject arguments; chain done / always as needed.
Piece
Required?
Role
Deferred / jqXHR
Yes
Object that can reject
failCallbacks
Yes
Function or array of functions
Return value
—
Same Deferred (chainable)
Pseudocode
Pseudocode
function fail(deferred, callbacks):
queue = flatten(callbacks) // functions and arrays
add each callback to failure list
when deferred.reject(args...):
for each fn in failure list (in order):
fn(args...)
return deferred // chainable
Reference
Cheat Sheet
Keep these facts handy while wiring error handlers.
Topic
Detail
Syntax
deferred.fail(failCallbacks [, failCallbacks ])
Since
jQuery 1.5 (catch alias since 3.0)
Runs when
Deferred is rejected
Arguments
Same values passed to reject / rejectWith
Multiple handlers
Functions or arrays; order preserved
Late attach
If already rejected → runs immediately
Returns
The Deferred (chainable)
Try it
Live Preview
Pick a scenario and see how fail() behaves on reject.
Browser demo of deferred.fail() — same ideas as the examples below.
Result
fail: Network error
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Settle first.reject happens before any handler is attached.
Attach late.fail(fn) sees the Deferred is already rejected.
Immediate call. jQuery invokes fn with the stored rejection reason.
Why it matters. Modules can attach listeners safely at different times.
Edge Cases & Pitfalls
Check these before relying on fail() alone.
path
No success coverage
fail() never runs on resolve. Always pair with done() or a fulfillment branch on then().
alias
catch needs jQuery 3+
catch() is an alias for fail() since 3.0. Stick with fail() if you still support jQuery 1.x / 2.x.
chain
fail vs then chaining
fail() returns the same Deferred. Prefer then(null, onRejected) or catch() when you need to recover and continue a promise chain.
once
Settled only once
A Deferred rejects or resolves once. Extra reject calls are ignored; late fail handlers still see the first reason.
Compatibility
Browser Support
deferred.fail() has shipped since jQuery 1.5 and works in all modern browsers with jQuery loaded. It is part of the Deferred Object API (also used by jqXHR). catch() as an alias needs jQuery 3.0+.
✓ jQuery 1.5+
deferred.fail()
Supported everywhere jQuery Deferred runs in the browser. Use it for error callbacks on Deferred and AJAX objects.
100%Browser support
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
fail()Excellent
Bottom line: Call dfd.fail(fn) for errors. Pair with done() for success. Works on Deferred and jqXHR since jQuery 1.5.
Analysis
Performance Notes
Approach
Cost
Best for
dfd.fail(fn)
O(k) handlers
Error-only side effects
dfd.catch(fn)
O(k) (alias)
Promise-style naming (3+)
dfd.always(fn)
O(k)
Shared cleanup
Handler cost is usually tiny compared with the async work (network, timers). Prefer clear success/error separation over micro-optimizing callback count.
Remember
Key Takeaways
Role: error callbacks when a Deferred is rejected.
Multi: pass functions or arrays; order is preserved.
Pair: use done() / always() for success and cleanup.
Alias:catch() ≡ fail() in jQuery 3+.
One line:dfd.fail(fn) runs on reject only — queue error work, and pair with done() for the success path.
Frequently Asked Questions
fail() registers one or more callbacks that run when the Deferred is rejected (failure). Handlers receive the values passed to reject() or rejectWith(), in registration order.
fail() runs only on reject. done() runs only on resolve. Pair them (or use then with two callbacks) so you cover both outcomes.
In jQuery 3.0+, catch() is an alias for fail() on Deferred and Promise objects. They behave the same — catch() exists for Promise-style naming.
Yes. Pass functions or arrays of functions. Callbacks run in the order they were added. You can also chain .fail().fail().
Yes. If the Deferred is already rejected, new fail() handlers fire immediately with the rejection reason.
Yes. jqXHR objects support .fail(function(xhr, status, error) { ... }) — the classic jQuery AJAX error-handler pattern.