jQuery .ajaxSuccess() Method

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is .ajaxSuccess()?

.ajaxSuccess(handler) is jQuery’s legacy shorthand (since 1.0) for binding a global Ajax “request succeeded” handler on document. It runs only on success — not on error. Internally it is sugar for .on("ajaxSuccess", handler).

Remember
// Deprecated (since 3.5)
$(document).ajaxSuccess(function (event, jqXHR, ajaxOptions, data) {
  // runs after every successful qualifying Ajax request
});

// Modern replacement
$(document).on("ajaxSuccess", handler);

// Bind only — no no-arg .ajaxSuccess() trigger form
// Opt out: $.ajax({ url: "/x", global: false })
NeedUse
New code$(document).on("ajaxSuccess", fn)
Legacy bind$(document).ajaxSuccess(fn) ⚠
Remove handler$(document).off("ajaxSuccess", fn)
Error onlyajaxError
Always finishedajaxComplete

How to Use .ajaxSuccess()

Recognize the legacy call, know its four handler arguments, and migrate to .on() / .off().

  1. Attach the handler to document with .ajaxSuccess(handler) (legacy) or .on("ajaxSuccess", handler) (preferred).
  2. Make requests with $.ajax(), $.get(), $.post(), or .load().
  3. Optionally filter with ajaxOptions.url; read jqXHR.responseText or parsed data.
  4. Remove with .off("ajaxSuccess", handler) — not .unbind().
  5. Use global: false on requests that must stay silent.
PieceRequired?Role
documentYes (1.9+)Only valid bind target for global Ajax events
handlerYesfunction(event, jqXHR, ajaxOptions, data)
ajaxOptions.urlOptionalFilter which requests you react to
global: falseOptionalSkip all global Ajax events for that call

Pseudocode

Pseudocode
call $(document).ajaxSuccess(handler)
    → internally: $(document).on("ajaxSuccess", handler)

when a jQuery Ajax request finishes:
    if request.global === false:
        do not fire ajaxSuccess
        return

    if request succeeded:
        fire ajaxSuccess
            for each registered handler:
                call handler(event, jqXHR, ajaxOptions, data)
    else:
        fire ajaxError instead

to migrate:
    replace .ajaxSuccess(fn) with .on("ajaxSuccess", fn)
    remove with .off("ajaxSuccess", fn)

Cheat Sheet

Quick map from legacy shorthand to modern APIs.

TopicDetail
Legacy bind$(document).ajaxSuccess(handler) ⚠ deprecated 3.5
Modern bind$(document).on("ajaxSuccess", handler)
Unbind$(document).off("ajaxSuccess" [, handler])
Signaturefunction(event, jqXHR, ajaxOptions, data)
WhenSuccessful requests only (not errors)
SinceMethod 1.0 · document-only 1.9+ · deprecated 3.5
Trigger formNone — bind only (unlike .click())
Opt outglobal: false in $.ajax() / $.ajaxSetup()

Live Preview

Run a real $.get() and watch the legacy .ajaxSuccess() handler update the log.

Demo uses deprecated .ajaxSuccess() plus a public JSON API. Needs network access.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets using the legacy shorthand. Prefer .on("ajaxSuccess") for new projects.

Example 1 — Basic $(document).ajaxSuccess(fn)

Canonical legacy pattern: log when any Ajax request succeeds after a click.

jQuery
$(document).ajaxSuccess(function () {
  $(".log").text("Handler ran via .ajaxSuccess(function(){ ... }).");
});

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

How It Works

  1. Bind. .ajaxSuccess(fn) on document registers a global handler.
  2. Delegate. jQuery routes it to .on("ajaxSuccess", fn) internally.
  3. Click. $.get() starts a qualifying Ajax request.
  4. Success. On a successful response, the log updates.

Example 2 — Filter by settings.url

Handlers run for every success — narrow them with the settings object.

jQuery
var targetUrl = "https://jsonplaceholder.typicode.com/posts/1";

$(document).ajaxSuccess(function (event, xhr, settings) {
  if (settings.url === targetUrl) {
    $(".log").text(
      "URL: " + settings.url + " | responseText: " +
      xhr.responseText.substring(0, 100) + "..."
    );
  }
});
Try It Yourself

How It Works

  1. Args. jQuery passes event, xhr, settings, and data.
  2. Compare. Check settings.url against the endpoint you care about.
  3. Read. Use xhr.responseText for the raw body (or data for parsed).
  4. Skip. Non-matching URLs leave your UI alone.

Example 3 — Append “Successful Request!”

Official-style demo: append a short status string for every successful request.

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

How It Works

  1. Global. One handler covers every qualifying successful Ajax call.
  2. Append. Each success adds another status fragment.
  3. Count. Parallel successes each fire their own success event.
  4. Migrate. Swap the bind to .on("ajaxSuccess") when refactoring.

Example 4 — Migrate to .on("ajaxSuccess")

Both bind the same global event — .on() is the recommended API for new code.

jQuery
// Legacy — deprecated since jQuery 3.5
$(document).ajaxSuccess(function () {
  $("#out").text("Legacy: .ajaxSuccess(function(){ ... }).");
});

// Modern — use for new code
$(document).on("ajaxSuccess", function () {
  $("#out").text("Modern: .on('ajaxSuccess', function(){ ... }).");
});
Try It Yourself

How It Works

  1. Same event. Both register handlers for ajaxSuccess on document.
  2. Sugar. .ajaxSuccess(fn) already calls .on("ajaxSuccess", fn).
  3. Rename. Migration is a straight API change for simple bindings.
  4. Cleanup. Pair modern binds with .off("ajaxSuccess", fn).

Example 5 — Remove Handler with .off()

Store a named function, then remove it with .off() — not deprecated .unbind().

jQuery
var count = 0;

function onSuccess() {
  count++;
  $(".log").text("Handler active — ajaxSuccess count: " + count);
}

$(document).ajaxSuccess(onSuccess);

$("#remove").on("click", function () {
  $(document).off("ajaxSuccess", onSuccess);
  $(".log").text("Handler removed — count stays " + count + ".");
});
Try It Yourself

How It Works

  1. Named fn. Anonymous handlers cannot be removed individually.
  2. Bind. .ajaxSuccess(onSuccess) stores that reference.
  3. Remove. .off("ajaxSuccess", onSuccess) detaches exactly that handler.
  4. Avoid. Do not use deprecated .unbind("ajaxSuccess") in new code.

Edge Cases & Pitfalls

Watch for these when reading or migrating legacy Ajax code.

deprecated

Do not use in new code

.ajaxSuccess(handler) is deprecated since 3.5. Prefer .on("ajaxSuccess").

target

Bind on document only (1.9+)

Handlers on window or other elements will not receive global Ajax events.

scope

Success only

Failed requests skip .ajaxSuccess(). Use ajaxError or ajaxComplete when outcome is not guaranteed.

trigger

No no-arg trigger form

Unlike .click(), calling .ajaxSuccess() with no arguments does not fire the event.

Browser Support

The .ajaxSuccess() method has been part of jQuery since 1.0. Since 1.9, handlers must attach to document. Binding via .ajaxSuccess(handler) is deprecated since 3.5 but still functional in jQuery 3.x.

✓ Deprecated · jQuery 1.0+

jQuery .ajaxSuccess()

Works wherever your loaded jQuery version runs Ajax. Prefer .on('ajaxSuccess') for new projects. fetch() and 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() Legacy API

Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('ajaxSuccess') and cleanup to .off('ajaxSuccess') when updating code.

Performance Notes

ApproachCostBest for
One filtered global handlerCheapSite-wide success toasts / logging
Per-request .done()CheapUI update for a single call
Heavy DOM work every successExpensiveAvoid — filter or debounce

Legacy and modern binds have the same cost. Keep handlers light, filter by URL before touching the DOM, and prefer .done() for request-specific work.

Key Takeaways

  • Role: legacy global “request succeeded” bind — not for errors.
  • Migrate: $(document).on("ajaxSuccess", fn) — preferred since 3.5.
  • Args: function(event, jqXHR, ajaxOptions, data) — filter with ajaxOptions.url.
  • Cleanup: use .off("ajaxSuccess", fn) — not .unbind().

One line: .ajaxSuccess() is deprecated sugar for .on("ajaxSuccess") on document.

Frequently Asked Questions

The .ajaxSuccess(handler) method binds a global function that runs whenever any qualifying jQuery Ajax request completes successfully. Attach it to document: $(document).ajaxSuccess(fn). It is bind-only (no trigger form). Deprecated since jQuery 3.5; use $(document).on("ajaxSuccess", handler) instead.
Yes. $(document).ajaxSuccess(handler) has been deprecated since jQuery 3.5 (available since 1.0). Prefer $(document).on("ajaxSuccess", handler) for new code. Legacy bindings still work in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off("ajaxSuccess", handler).
ajaxSuccess is a global Ajax event, not a DOM event on a specific element. Since jQuery 1.9, all global Ajax handlers — including .ajaxSuccess(handler) — must bind to document. Correct legacy form: $(document).ajaxSuccess(fn). Modern form: $(document).on("ajaxSuccess", fn).
Four — the same as the ajaxSuccess event: function(event, jqXHR, ajaxOptions, data). Use jqXHR.responseText for the raw body, data for the processed response, and ajaxOptions.url to identify the request. Failed requests trigger ajaxError instead.
Replace $(document).ajaxSuccess(fn) with $(document).on("ajaxSuccess", fn). Use $(document).off("ajaxSuccess", fn) for cleanup instead of .unbind(). Under the hood, .ajaxSuccess(handler) already delegates to .on("ajaxSuccess") — migration is a straight rename for simple bindings.
Yes. jQuery 3.x keeps .ajaxSuccess(handler) for backward compatibility. It still binds correctly on document. Docs mark it deprecated since 3.5 to steer new projects toward .on(). Prefer the modern API covered in the jQuery ajaxSuccess event tutorial.

Next: ajaxComplete event

Global handler that runs after every finished request — success or error.

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

8 people found this page helpful