.ajaxStop(handler) is jQuery’s legacy shorthand (since 1.0) for binding a global Ajax “batch idle” handler on document. It runs when the last qualifying request finishes and none remain active. Internally it is sugar for .on("ajaxStop", handler).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Deprecated (since 3.5)
$(document).ajaxStop(function () {
// runs when no global Ajax requests remain active
});
// Modern replacement
$(document).on("ajaxStop", handler);
// Bind only — no no-arg .ajaxStop() trigger form
// Opt out: $.ajax({ url: "/x", global: false })
Call
What it does
document
Only valid bind target for global Ajax events
handler
function() — no extra arguments
ajaxStart
Show loading UI when the first request begins
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 .ajaxStop(handler) (legacy) or .on("ajaxStop", handler) (preferred).
Step 2
Pair with ajaxStart if you show a spinner when activity begins.
Step 3
Remember: the handler is function() — no jqXHR / 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 — Basic $(document).ajaxStop(fn)
Canonical legacy pattern: log when global Ajax activity ends after a click.
jQuery
$(document).ajaxStop(function () {
$(".log").text("Handler ran via .ajaxStop(function(){ ... }).");
});
$("#fetch").on("click", function () {
$.get("https://jsonplaceholder.typicode.com/posts/1");
});
Click #run-two → two parallel $.get()
stopCount increments by 1 (not 2)
ajaxComplete would fire twice
How It Works
Counter. jQuery tracks active global requests internally.
Overlap. The second call keeps the count above zero.
Idle. When both finish, the count hits zero → one ajaxStop.
Frequently Asked Questions
The .ajaxStop(handler) method binds a global function that runs when all qualifying jQuery Ajax requests have completed — when no global requests remain active. Attach it to document: $(document).ajaxStop(fn). It is bind-only (no trigger form). Deprecated since jQuery 3.5; use $(document).on("ajaxStop", handler) instead.
Yes. $(document).ajaxStop(handler) has been deprecated since jQuery 3.5 (available since 1.0). Prefer $(document).on("ajaxStop", handler) for new code. Legacy bindings still work in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off("ajaxStop", handler).
ajaxStop is a global Ajax event, not a DOM event on a specific element. Since jQuery 1.9, all global Ajax handlers — including .ajaxStop(handler) — must bind to document. Correct legacy form: $(document).ajaxStop(fn). Modern form: $(document).on("ajaxStop", fn).
None. The official API lists handler as Function() with no parameters — function() { ... }. Unlike ajaxComplete, you do not receive event, jqXHR, or ajaxOptions. Use ajaxComplete for per-request details.
Replace $(document).ajaxStop(fn) with $(document).on("ajaxStop", fn). Use $(document).off("ajaxStop", fn) for cleanup instead of .unbind(). Under the hood, .ajaxStop(handler) already delegates to .on("ajaxStop") — migration is a straight rename for simple bindings.
.ajaxStop() fires once when the last global request finishes — ideal for hiding page-wide loading UI. ajaxComplete fires after every individual request and receives (event, jqXHR, ajaxOptions). Pair .ajaxStop() with .ajaxStart() (or their .on() equivalents) to show and hide loading UI for a batch.