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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
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
Call
What it does
Deferred / jqXHR
Object that can reject
failCallbacks
Function or array of functions
Return value
Same Deferred (chainable)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Get a Deferred (e.g. $.Deferred()) or a jqXHR from $.ajax / $.get.
Step 2
Call .fail(function (reason) { ... }) — pass a function or an array of functions.
Step 3
When failure happens, call reject(reason) (or let AJAX fail).
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Multi-arg reject. jQuery forwards every argument to each fail callback.
AJAX shape. Real $.ajax().fail often gets (jqXHR, textStatus, errorThrown).
Parameter list. Match them left-to-right in your handler.
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.