.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).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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 })
Call
What it does
document
Only valid bind target for global Ajax events
handler
function(event, jqXHR, ajaxOptions, data)
ajaxOptions.url
Filter which 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 .ajaxSuccess(handler) (legacy) or .on("ajaxSuccess", handler) (preferred).
Step 2
Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3
Optionally filter with ajaxOptions.url; read jqXHR.responseText or parsed data.
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 — 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");
});
Each successful request →
#msg gains " Successful Request! "
Three parallel successes → three appends
How It Works
Global. One handler covers every qualifying successful Ajax call.
Append. Each success adds another status fragment.
Count. Parallel successes each fire their own success event.
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.