jQuery .ajaxStop() Method

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

What Is .ajaxStop()?

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

Remember
// 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 })
NeedUse
New code$(document).on("ajaxStop", fn)
Legacy bind$(document).ajaxStop(fn) ⚠
Remove handler$(document).off("ajaxStop", fn)
Show loadingajaxStart
Every finished requestajaxComplete

How to Use .ajaxStop()

Recognize the legacy call, know it has no handler args, and migrate to .on() / .off().

  1. Attach the handler to document with .ajaxStop(handler) (legacy) or .on("ajaxStop", handler) (preferred).
  2. Pair with ajaxStart if you show a spinner when activity begins.
  3. Remember: the handler is function() — no jqXHR / settings.
  4. Remove with .off("ajaxStop", 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() — no extra arguments
ajaxStartRecommendedShow loading UI when the first request begins
global: falseOptionalSkip all global Ajax events for that call

Pseudocode

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

when a jQuery Ajax request finishes:
    if request.global === false:
        do not count it / do not fire ajaxStop for it
        return

    decrement active global request count
    fire ajaxComplete for this request

    if active global request count === 0:
        fire ajaxStop
            for each registered handler:
                call handler()

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

Cheat Sheet

Quick map from legacy shorthand to modern APIs.

TopicDetail
Legacy bind$(document).ajaxStop(handler) ⚠ deprecated 3.5
Modern bind$(document).on("ajaxStop", handler)
Unbind$(document).off("ajaxStop" [, handler])
Signaturefunction() — no jqXHR / settings
WhenLast global request ends (active count → 0)
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 .ajaxStop() handler update the log.

Demo uses deprecated .ajaxStop() 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("ajaxStop") for new projects.

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.
  4. Idle. When that request finishes and none remain, the log updates.

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.
  4. Migrate. Prefer .on("ajaxStop") when you rewrite this.

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.
  4. Choose. Need every finish? Use ajaxComplete instead.

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

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

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

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

How It Works

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

Example 5 — Remove Handler with .off()

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

jQuery
var count = 0;

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

$(document).ajaxStop(onStop);

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

How It Works

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

Edge Cases & Pitfalls

Watch for these when reading or migrating legacy Ajax code.

deprecated

Do not use in new code

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

target

Bind on document only (1.9+)

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

args

No jqXHR / settings

The handler is function(). Read response details from ajaxComplete instead.

trigger

No no-arg trigger form

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

Browser Support

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

✓ Deprecated · jQuery 1.0+

jQuery .ajaxStop()

Works wherever your loaded jQuery version runs Ajax. Prefer .on('ajaxStop') 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
.ajaxStop() Legacy API

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

Performance Notes

ApproachCostBest for
One light .ajaxStop() (toggle UI)CheapPage-wide loading spinner
ajaxStart + ajaxStop pairCheapShow / hide loading for a batch
Heavy DOM work on every stopExpensiveAvoid — keep the handler tiny

Legacy and modern binds have the same cost. Keep handlers light — toggle visibility only — and prefer ajaxComplete for per-request work.

Key Takeaways

  • Role: legacy global “batch idle” bind — hide loading UI.
  • Migrate: $(document).on("ajaxStop", fn) — preferred since 3.5.
  • Args: function() — no jqXHR; use ajaxComplete for details.
  • Cleanup: use .off("ajaxStop", fn) — not .unbind().

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

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: deferred.done()

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

deferred.done() 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