The ajaxSuccess event fires when a qualifying jQuery Ajax request succeeds — not on failure. This tutorial covers binding on document with .on("ajaxSuccess"), the handler signature (event, jqXHR, ajaxOptions, data), filtering by ajaxOptions.url, reading xhr.responseText and the parsed data argument, opting out with global: false, and comparing global events with per-request .done().
01
Global
AjaxEvent
02
document
Bind target
03
Success
2xx only
04
settings
Filter URL
05
global:false
Opt out
06
Since 1.7
.on() API
Fundamentals
Introduction
When your page loads data with $.ajax(), $.get(), $.post(), or .load(), jQuery broadcasts lifecycle events to listeners on document. The ajaxSuccess event is your global “request succeeded” hook — it fires only when a qualifying request completes successfully.
The official jQuery API distinguishes the ajaxSuccessevent (bound with .on("ajaxSuccess") since 1.7) from the deprecated .ajaxSuccess()method used in older code. Unlike ajaxComplete, which runs for both success and failure, ajaxSuccess is outcome-specific — failed requests trigger ajaxError instead. On successful requests, ajaxSuccess runs beforeajaxComplete.
Concept
Understanding the ajaxSuccess Event
ajaxSuccess is classified as an AjaxEvent — a global event triggered by jQuery’s Ajax transport, not a DOM event on a specific element. Whenever an Ajax request completes successfully, jQuery triggers ajaxSuccess on document. Handlers receive four arguments: the native event object, the jqXHR object, ajaxOptions — the settings used to create the request — and data, the processed response (parsed JSON, HTML fragment, etc.).
Every registered ajaxSuccess handler runs for every successful qualifying request. Read the raw body with jqXHR.responseText or use the fourth argument data when jQuery has already parsed it. To react only to certain URLs, inspect ajaxOptions.url inside the handler.
💡
Beginner Tip
Bind once on $(document).on("ajaxSuccess", fn) instead of adding a .done() callback to every $.ajax() call when you need site-wide success toasts or analytics. Use global: false on requests that should not notify global listeners — for example, silent prefetch or third-party widgets.
Foundation
📝 Syntax
The modern jQuery API for the ajaxSuccess global event:
1. Bind a handler — $(document).on("ajaxSuccess" [, handler]) (since 1.7)
jQuery
$( document ).on( "ajaxSuccess", handler )
handler — function invoked when any qualifying Ajax request succeeds: function( event, jqXHR, ajaxOptions, data ) { ... }.
event — the jQuery event object.
jqXHR — the jqXHR / XMLHttpRequest object; read jqXHR.responseText for the response body.
The old .ajaxSuccess(handler) binding method still works but is deprecated. Migrate to $(document).on("ajaxSuccess", handler) for consistency with other events and reliable unbinding via .off().
Return value
.on("ajaxSuccess", handler) returns the jQuery object (document wrapped) for chaining.
Handler return values are ignored by jQuery’s global Ajax event system.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind global success handler
$(document).on("ajaxSuccess", fn)
Handler signature
function(event, jqXHR, ajaxOptions, data)
Read response text
jqXHR.responseText
Read parsed response
data (4th handler argument)
Filter by URL
if (ajaxOptions.url === "/api/x")
Opt out of global events
$.ajax({ url: "/x", global: false })
Per-request success
$.ajax(...).done(fn)
Remove handlers
$(document).off("ajaxSuccess")
Compare
📋 ajaxSuccess vs .done() vs ajaxComplete / ajaxError
Four ways to react when an Ajax request succeeds — choose global vs per-request and outcome-specific vs always-finish hooks.
ajaxSuccess
global
Document event — runs for every qualifying successful request only
.done()
per call
jqXHR callback — runs once when a single $.ajax() call succeeds
ajaxComplete
always
Global event — fires after success or error
ajaxError
fail only
Global event — fires only when the request fails
Global event order for each request: ajaxStart → ajaxSend → ajaxSuccess | ajaxError → ajaxComplete → ajaxStop. ajaxStart and ajaxStop bracket the set of active global requests — they fire when the first request begins and when the last one finishes.
Hands-On
Examples Gallery
Examples 1, 3, and 4 follow the official jQuery API documentation. Examples 2 and 5 extend those patterns with URL filtering and a success-only comparison with a failing request. Use the Try-it links to run each snippet in the browser.
📚 Official Patterns
Document-level handlers that observe every qualifying successful Ajax request.
Example 1 — Official Demo: Document Handler + $.get() on Click
Attach ajaxSuccess on document, then trigger a successful Ajax request with $.get() when the user clicks a button.
User clicks #fetch → $.get() runs Ajax request
When request succeeds → .log shows "Triggered ajaxSuccess handler."
Failed requests do not trigger ajaxSuccess — use ajaxError instead
How It Works
$.get() is a shorthand for $.ajax(), so it triggers global Ajax events on success. The ajaxSuccess handler on document runs when the server returns a successful response — before ajaxComplete.
Example 2 — Filter by settings.url
All ajaxSuccess handlers run for every successful request — use ajaxOptions.url to narrow the callback to one endpoint.
jQuery
$( document ).on( "ajaxSuccess", function( event, xhr, settings ) {
if ( settings.url === "ajax/test.html" ) {
$( ".log" ).text( "Triggered ajaxSuccess handler. The result is " +
xhr.responseText );
}
} );
Request to ajax/test.html completes → .log shows handler message + responseText
Request to other URLs → handler runs but if-block skipped
Use settings.type, settings.context, or custom keys to filter further
How It Works
jQuery passes the same settings object used in $.ajax(settings) as the third argument. Compare settings.url (or a custom property you add to settings) before updating the DOM or logging.
Example 3 — Official Demo: Append “Successful Request!” to #msg
Show a message in the page whenever any Ajax request completes successfully.
Each successful Ajax request → #msg gains " Successful Request! "
Three parallel successful requests → three appended messages
Failed requests do not append — only successes trigger ajaxSuccess
How It Works
Because ajaxSuccess fires only on success, appending to #msg builds a running log of successful calls. Pair with URL filtering if you only want messages for specific endpoints.
📈 Opt-Out & Per-Request Comparison
global: false and when to prefer .done() over global events.
Example 4 — global: false — Event Does Not Fire
Requests with global: false skip all global Ajax events, including ajaxSuccess.
Click #global-btn → ajaxSuccess fires → log updated
Click #private-btn → request completes but ajaxSuccess does NOT fire
Per-request .done() on the private call still runs
How It Works
Setting global: false on an individual $.ajax() call (or via $.ajaxSetup({ global: false })) opts that request out of ajaxStart, ajaxSend, ajaxSuccess, ajaxError, ajaxComplete, and ajaxStop.
Example 5 — Success Only: ajaxSuccess vs Failed Request
A global counter increments only on successful requests — a deliberate 404 triggers ajaxError, not ajaxSuccess.
Click #ok → ajaxSuccess count goes to 1
Click #fail → request fails → count stays at 1
ajaxError fires instead; ajaxComplete still runs after the failure
Use ajaxSuccess when you only care about successful responses
How It Works
ajaxSuccess is ideal for global success toasts, cache warming, or analytics that should ignore expected failures. For per-request success UI, chain .done() on the jqXHR. Use ajaxComplete when you need both outcomes.
Applications
🚀 Common Use Cases
Success toasts — show “Saved successfully” when ajaxSuccess fires for form submissions.
Analytics hooks — send timing or URL data to monitoring when ajaxSuccess fires, filtered by settings.url.
Cache warming — prefetch related data when a list endpoint succeeds globally.
Response inspection — read xhr.responseText in a global handler for logging (avoid parsing large bodies on every request in production).
Third-party isolation — set global: false on widget requests so they do not trigger your global ajaxSuccess logic.
Testing — assert that a test harness saw the expected number of successful requests via a global counter.
🧠 Where ajaxSuccess Fits in the Event Order
1
ajaxStart
First active global request begins — show a page-wide loading indicator.
ajaxStart
2
ajaxSend
Just before the request is sent — last chance to modify headers globally.
ajaxSend
3
ajaxSuccess or ajaxError
Outcome-specific global event — success handler or error handler runs.
success | error
4
ajaxComplete
Always runs after step 3 — all registered ajaxComplete handlers execute.
ajaxComplete
5
👉
ajaxStop
Last active global request finished — hide the loading indicator.
Important
📝 Notes
Bind with $(document).on("ajaxSuccess", handler) since jQuery 1.7 — not the deprecated .ajaxSuccess(handler) method.
Since jQuery 1.9, attach global Ajax handlers to document — not window.
ajaxSuccess fires only on success — before ajaxComplete, which runs for both outcomes.
Every registered handler runs for every successful qualifying request.
Requests with global: false do not trigger ajaxSuccess.
Read the response with jqXHR.responseText (official docs use parameter name xhr).
Use the fourth argument data for parsed JSON when dataType: "json".
Differentiate requests with ajaxOptions.url, ajaxOptions.type, or custom settings properties.
For per-request success UI, prefer $.ajax(...).done(fn) over a global handler with heavy filtering.
Compatibility
Browser Support
The ajaxSuccess event is a jQuery global Ajax event — not a native DOM event. It works wherever jQuery’s Ajax transport runs: all browsers supported by your jQuery version. Bind with .on("ajaxSuccess") since 1.7; attach handlers to document since 1.9.
✓ jQuery 1.7+
jQuery ajaxSuccess event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Requires jQuery Ajax — requests made with fetch() or axios do not trigger jQuery global events.
100%With jQuery Ajax
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
ajaxSuccessUniversal
Bottom line: Safe in any jQuery project using $.ajax(), $.get(), $.post(), or .load(). Prefer .on('ajaxSuccess') over deprecated .ajaxSuccess(). Fires only on success — use ajaxComplete for both outcomes.
Wrap Up
Conclusion
The jQuery ajaxSuccess event is the global “request succeeded” hook — it runs when a qualifying Ajax call completes successfully. Bind handlers on document with .on("ajaxSuccess", fn), inspect ajaxOptions to filter by URL, and use the data argument or jqXHR.responseText for the response.
Remember the event order: ajaxSuccess on success (or ajaxError on failure), then ajaxComplete, then ajaxStop when no global requests remain. Use global: false to opt out. Continue with the .ajaxSuccess() method tutorial for the deprecated shorthand API.
Filter with ajaxOptions.url when the handler should not run for every request
Pair with ajaxStart / ajaxStop for loading indicators
Use global: false for silent background or third-party requests
Remove handlers with $(document).off("ajaxSuccess") on SPA teardown
❌ Don’t
Attach global handlers to window — use document since jQuery 1.9
Use deprecated .ajaxSuccess(handler) in new code
Expect ajaxSuccess on failed requests — use ajaxError or ajaxComplete instead
Parse large responseText in every global handler — hurts performance
Duplicate per-request .done() logic inside a global handler without filtering
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about ajaxSuccess
Global, success-only, on document.
6
Core concepts
doc01
document
Bind here
Global
✓✗02
Success
2xx only
Behavior
url03
settings
Filter
ajaxOptions
data04
data
4th argument
Parsed
off05
global:false
Opt out
Private
.on06
.on()
Not .ajaxSuccess()
Modern
❓ Frequently Asked Questions
ajaxSuccess is a global Ajax event (AjaxEvent) that fires whenever any qualifying jQuery Ajax request completes successfully. Bind handlers with $(document).on('ajaxSuccess', handler) since version 1.7. Every registered handler runs for every successful request — failed requests trigger ajaxError instead.
Since jQuery 1.9, all global Ajax event handlers — including ajaxSuccess — must be bound to document, not window or other elements. Use $(document).on('ajaxSuccess', fn) and $(document).off('ajaxSuccess', fn) to remove them.
No. ajaxSuccess runs only when a request succeeds (HTTP 2xx and successful transport). Failed requests trigger ajaxError instead. ajaxComplete fires for both outcomes — after ajaxSuccess or ajaxError.
ajaxSuccess is a global document event — one handler observes every qualifying successful request on the page. done() is per-request on the jqXHR returned by $.ajax() — it runs only for that single call. Use global events for site-wide success toasts; use done() for request-specific UI updates.
When $.ajax() or $.ajaxSetup() sets global: false, that request opts out of all global Ajax events. ajaxSuccess will not fire for it. Per-request done(), fail(), and always() callbacks still run normally.
Four arguments: function(event, jqXHR, ajaxOptions, data). The event object is the jQuery event; jqXHR is the XMLHttpRequest wrapper; ajaxOptions is the settings object used to create the request; data is the processed response (parsed JSON, HTML, etc.) based on dataType.
Did you know?
jQuery passes a fourth argument data to ajaxSuccess handlers — the parsed response based on dataType. For JSON requests, data is already an object; you can still read xhr.responseText for the raw string. The deprecated .ajaxSuccess(fn) method is equivalent to .on("ajaxSuccess", fn); jQuery 1.7 unified binding under .on() alongside mouse and keyboard events.