jQuery .ajaxStart() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.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 })
CallWhat it does
documentOnly valid bind target for global Ajax events
handlerfunction() — no request args
ajaxStopHide loading when no global requests remain
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 .ajaxStart(handler) (legacy) or .on("ajaxStart", handler) (preferred).
Step 2Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3Show a spinner or status text inside the handler (no jqXHR args).

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).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");
});
Try It Yourself

How It Works

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

Example 2 — Show a Loading Message

Common legacy pattern: write a loading status when global Ajax activity begins.

jQuery
$(document).ajaxStart(function () {
  $("#loading").text("Loading…");
});

$("#go").on("click", function () {
  $.get("https://jsonplaceholder.typicode.com/posts/1");
});
Try It Yourself

How It Works

  1. Handler. On start, write a loading message into #loading.
  2. Trigger. Any qualifying Ajax call can light up the UI.
  3. No args. You do not need jqXHR — this is page-wide UI only.

Example 3 — Parallel Requests Fire Once

Three overlapping calls still produce a single ajaxStart.

jQuery
var startCount = 0;

$(document).ajaxStart(function () {
  startCount++;
  $("#log").text("ajaxStart count: " + startCount);
});

$("#go").on("click", function () {
  $.get("https://jsonplaceholder.typicode.com/posts/1");
  $.get("https://jsonplaceholder.typicode.com/posts/2");
  $.get("https://jsonplaceholder.typicode.com/posts/3");
});
Try It Yourself

How It Works

  1. Idle → busy. The first request finds no active globals and fires start.
  2. Already busy. The next two see activity in progress — no extra start.
  3. 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.

Next: ajaxSend Event

Learn the per-request global event that fires before every Ajax send.

ajaxSend Event 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.

7 people found this page helpful