jQuery .ajaxStop() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.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 })
CallWhat it does
documentOnly valid bind target for global Ajax events
handlerfunction() — no extra arguments
ajaxStartShow loading UI when the first request begins
global: falseSkip 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

ParameterDescription
Step 1Attach the handler to document with .ajaxStop(handler) (legacy) or .on("ajaxStop", handler) (preferred).
Step 2Pair with ajaxStart if you show a spinner when activity begins.
Step 3Remember: the handler is function() — no jqXHR / settings.

Return Value

Return ValueDescription
jQuery objectMost 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");
});
Try It Yourself

How It Works

  1. Bind. .ajaxStop(fn) on document registers a global handler.
  2. Delegate. jQuery routes it to .on("ajaxStop", fn) internally.
  3. Click. $.get() starts a qualifying Ajax request.

Example 2 — Hide #loading

Official-style demo: hide a loading message when all Ajax activity ends.

jQuery
$(document).ajaxStop(function () {
  $("#loading").hide();
});
Try It Yourself

How It Works

  1. Role. .ajaxStop() is the hide hook for page-wide loading UI.
  2. Once. Parallel requests share one hide — not one per call.
  3. Pair. Use ajaxStart to show #loading when work begins.

Example 3 — Parallel Requests Fire Once

Two $.get() calls at once — .ajaxStop() increments only when both finish.

jQuery
var stopCount = 0;

$(document).ajaxStop(function () {
  stopCount++;
  $("#stop-count").text(stopCount);
});

$("#run-two").on("click", function () {
  $.get("/api/a");
  $.get("/api/b");
});

// After both finish: stopCount === 1 (not 2)
Try It Yourself

How It Works

  1. Counter. jQuery tracks active global requests internally.
  2. Overlap. The second call keeps the count above zero.
  3. 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.

Next: Callbacks Methods

Attach callbacks when a Deferred resolves — common after Ajax success paths.

Callbacks Methods tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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