ajaxError is a global AjaxEvent (since jQuery 1.0; .on() binding since 1.7). jQuery triggers it on document whenever a qualifying Ajax request fails. All registered handlers run.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$(document).on("ajaxError", function (event, jqXHR, ajaxSettings, thrownError) {
// runs only when a qualifying Ajax request fails
});
// Order (on failure):
// ajaxError → ajaxComplete → (ajaxStop when idle)
// Opt out for one call:
$.ajax({ url: "/x", global: false });
// Not fired for cross-domain script / JSONP requests
Call
What it does
document
Only valid bind target for global Ajax events
handler
function(event, jqXHR, ajaxSettings, thrownError)
ajaxSettings.url
Filter which failed requests you react to
global: false
Skip all global Ajax events for that call
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Attach the handler to document with .on("ajaxError", handler).
Step 2
Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3
Optionally filter with ajaxSettings.url (or other settings).
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 — Document Handler + Failing .load()
Official pattern: log a message when an Ajax request fails after a click.
jQuery
$(document).on("ajaxError", function () {
$(".log").text("Triggered ajaxError handler.");
});
$(".trigger").on("click", function () {
$(".result").load("ajax/missing.html");
});
Each failed request →
#msg gains " Error requesting page … "
Two parallel failures → two appends
How It Works
Global. One handler covers every qualifying failed Ajax call.
Append. Each failure adds another status fragment with the URL.
Count. Parallel failures each fire their own ajaxError.
Frequently Asked Questions
ajaxError is a global AjaxEvent that fires whenever a qualifying jQuery Ajax request completes with an error — HTTP failures, transport errors, or parser errors. Bind it with $(document).on("ajaxError", handler) (since 1.7). Every registered handler runs for every failed request.
Since jQuery 1.9, all global Ajax event handlers must be bound to document — not window or other elements. Use $(document).on("ajaxError", fn) and remove with $(document).off("ajaxError", fn).
No. ajaxError runs only when a request fails. Successful responses trigger ajaxSuccess instead. Both are followed by ajaxComplete. Use ajaxError for global error UI; use ajaxSuccess when you only care about success.
ajaxError is a global document event — one handler observes every qualifying failed request on the page. fail() is per-request on the jqXHR from $.ajax() — it runs only for that call. Use global events for site-wide error UI; use fail() for request-specific handling.
When $.ajax() or $.ajaxSetup() sets global: false, that request opts out of all global Ajax events. ajaxError will not fire for it. Per-request fail() and always() still run.
The fourth handler argument, thrownError, receives the textual portion of the HTTP status when an HTTP error occurs — for example "Not Found" for 404 or "Internal Server Error" for 500. Pair it with jqXHR.status (the numeric code).
The shorthand method .ajaxError(handler) is deprecated as of jQuery 3.5. Prefer $(document).on("ajaxError", handler) — the event API this page teaches.