.ajaxStart(handler) is jQuery’s legacy shorthand (since 1.0) for binding a global Ajax “first request began” handler on document. It fires only when no other global requests are already active. Internally it is sugar for .on("ajaxStart", handler).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Deprecated (since 3.5)
$(document).ajaxStart(function () {
// runs when the first global Ajax request begins
});
// Modern replacement
$(document).on("ajaxStart", handler);
// Bind only — no no-arg .ajaxStart() 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 request args
ajaxStop
Hide loading when no global requests remain
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 .ajaxStart(handler) (legacy) or .on("ajaxStart", handler) (preferred).
Step 2
Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3
Show a spinner or status text inside the handler (no jqXHR args).
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).ajaxStart(fn)
Canonical legacy pattern: log when the first Ajax request begins after a click.
jQuery
$(document).ajaxStart(function () {
$(".log").text("Handler ran via .ajaxStart(function(){ ... }).");
});
$("#fetch").on("click", function () {
$.get("https://jsonplaceholder.typicode.com/posts/1");
});
Three $.get() calls start together
ajaxStart count → 1 (not 3)
Second click while idle → count goes to 2
How It Works
Idle → busy. The first request finds no active globals and fires start.
Already busy. The next two see activity in progress — no extra start.
Count. Your counter increments once per batch, not per call.
Frequently Asked Questions
The .ajaxStart(handler) method binds a global function that runs when the first qualifying jQuery Ajax request is about to begin — and only when no other global requests are already in progress. Attach it to document: $(document).ajaxStart(fn). It is bind-only (no trigger form). Deprecated since jQuery 3.5; use $(document).on("ajaxStart", handler) instead.
Yes. $(document).ajaxStart(handler) has been deprecated since jQuery 3.5 (available since 1.0). Prefer $(document).on("ajaxStart", handler) for new code. Legacy bindings still work in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off("ajaxStart", handler).
ajaxStart is a global Ajax event, not a DOM event on a specific element. Since jQuery 1.9, all global Ajax handlers — including .ajaxStart(handler) — must bind to document. Correct legacy form: $(document).ajaxStart(fn). Modern form: $(document).on("ajaxStart", fn).
None. The official API lists handler as Function() with no parameters — function() { … }. Unlike ajaxSend, you do not receive event, jqXHR, or settings. Use ajaxSend when you need per-request details.
Replace $(document).ajaxStart(fn) with $(document).on("ajaxStart", fn). Use $(document).off("ajaxStart", fn) for cleanup instead of .unbind(). Under the hood, .ajaxStart(handler) already delegates to .on("ajaxStart") — migration is a straight rename for simple bindings.
Yes. jQuery 3.x keeps .ajaxStart(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 ajaxStart event tutorial.