jQuery ajaxSuccess Event

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Ajax events

What You’ll Learn

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

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 ajaxSuccess event (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 before ajaxComplete.

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.

📝 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.
  • ajaxOptions — settings passed to $.ajax() (url, type, data, context, etc.).
  • data — processed response data (parsed JSON, HTML, text) based on dataType.

2. Official demo — document handler + $.get() on click

jQuery
$( document ).on( "ajaxSuccess", function() {
  $( ".log" ).text( "Triggered ajaxSuccess handler." );
} );

$( "#fetch" ).on( "click", function() {
  $.get( "https://jsonplaceholder.typicode.com/posts/1" );
} );

3. Filter by URL — inspect ajaxOptions

jQuery
$( document ).on( "ajaxSuccess", function( event, xhr, settings ) {
  if ( settings.url === "ajax/test.html" ) {
    $( ".log" ).text( "Triggered ajaxSuccess handler. The result is " +
      xhr.responseText );
  }
} );

4. Unbind — $(document).off("ajaxSuccess" [, handler])

jQuery
$( document ).off( "ajaxSuccess" );              // remove all ajaxSuccess handlers
$( document ).off( "ajaxSuccess", myHandler );   // remove one handler

5. Deprecated method — .ajaxSuccess(handler)

jQuery
// Deprecated — use .on("ajaxSuccess") instead
$( document ).ajaxSuccess( function( event, xhr, settings ) {
  console.log( "Request succeeded:", settings.url );
} );

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.

⚡ Quick Reference

GoalCode
Bind global success handler$(document).on("ajaxSuccess", fn)
Handler signaturefunction(event, jqXHR, ajaxOptions, data)
Read response textjqXHR.responseText
Read parsed responsedata (4th handler argument)
Filter by URLif (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")

📋 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: ajaxStartajaxSendajaxSuccess | ajaxErrorajaxCompleteajaxStop. ajaxStart and ajaxStop bracket the set of active global requests — they fire when the first request begins and when the last one finishes.

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.

jQuery
$( document ).on( "ajaxSuccess", function() {
  $( ".log" ).text( "Triggered ajaxSuccess handler." );
} );

$( "#fetch" ).on( "click", function() {
  $.get( "https://jsonplaceholder.typicode.com/posts/1" );
} );
Try It Yourself

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 );
  }
} );
Try It Yourself

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.

jQuery
$( document ).on( "ajaxSuccess", function( event, request, settings ) {
  $( "#msg" ).append( " Successful Request! " );
} );
Try It Yourself

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.

jQuery
var globalCount = 0;

$( document ).on( "ajaxSuccess", function() {
  globalCount++;
  $( "#log" ).append( " ajaxSuccess (" + globalCount + ")" );
} );

$( "#global-btn" ).on( "click", function() {
  $.get( "https://jsonplaceholder.typicode.com/posts/1" );
} );

$( "#private-btn" ).on( "click", function() {
  $.ajax( { url: "https://jsonplaceholder.typicode.com/posts/2", global: false } );
} );
Try It Yourself

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.

jQuery
var successCount = 0;

$( document ).on( "ajaxSuccess", function() {
  successCount++;
  $( "#log" ).text( "ajaxSuccess count: " + successCount );
} );

$( "#ok" ).on( "click", function() {
  $.get( "https://jsonplaceholder.typicode.com/posts/1" );
} );

$( "#fail" ).on( "click", function() {
  $.get( "https://httpbin.org/status/404" );
} );
Try It Yourself

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.

🚀 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.

📝 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
ajaxSuccess Universal

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.

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.

💡 Best Practices

✅ Do

  • Bind on $(document).on("ajaxSuccess", handler)
  • 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

Key Takeaways

Knowledge Unlocked

Six things to remember about ajaxSuccess

Global, success-only, on document.

6
Core concepts
✓✗ 02

Success

2xx only

Behavior
url 03

settings

Filter

ajaxOptions
data 04

data

4th argument

Parsed
off 05

global:false

Opt out

Private
.on 06

.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.

Next: .ajaxSuccess() Method

Learn the deprecated shorthand for binding global ajaxSuccess handlers in legacy jQuery code.

.ajaxSuccess() method tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful