jQuery .ajaxSend() Method

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

What Is .ajaxSend()?

.ajaxSend(handler) is jQuery’s legacy shorthand (since 1.0) for binding a global Ajax “about to send” handler on document. It runs just before every qualifying request leaves the browser. Internally it is sugar for .on("ajaxSend", handler).

Remember
// Deprecated (since 3.5)
$(document).ajaxSend(function (event, jqXHR, ajaxOptions) {
  // runs just before every qualifying Ajax request is sent
});

// Modern replacement
$(document).on("ajaxSend", handler);

// Bind only — no no-arg .ajaxSend() trigger form
// Opt out: $.ajax({ url: "/x", global: false })
NeedUse
New code$(document).on("ajaxSend", fn)
Legacy bind$(document).ajaxSend(fn) ⚠
Remove handler$(document).off("ajaxSend", fn)
One request only$.ajax({ beforeSend: fn })
After request finishesajaxComplete

How to Use .ajaxSend()

Recognize the legacy call, know its three handler arguments, and migrate to .on() / .off().

  1. Attach the handler to document with .ajaxSend(handler) (legacy) or .on("ajaxSend", handler) (preferred).
  2. Make requests with $.ajax(), $.get(), $.post(), or .load().
  3. Optionally filter with ajaxOptions.url (response is not available yet).
  4. Remove with .off("ajaxSend", 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(event, jqXHR, ajaxOptions)
ajaxOptions.urlOptionalFilter which requests you react to
global: falseOptionalSkip all global Ajax events for that call

Pseudocode

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

when a jQuery Ajax request is about to be sent:
    if request.global === false:
        do not fire ajaxSend
        return

    fire ajaxSend
        for each registered handler:
            call handler(event, jqXHR, ajaxOptions)

    send the HTTP request
    // response is not available yet

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

Cheat Sheet

Quick map from legacy shorthand to modern APIs.

TopicDetail
Legacy bind$(document).ajaxSend(handler) ⚠ deprecated 3.5
Modern bind$(document).on("ajaxSend", handler)
Unbind$(document).off("ajaxSend" [, handler])
Signaturefunction(event, jqXHR, ajaxOptions)
WhenJust before each qualifying request is sent
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 .ajaxSend() handler update the log before the request leaves.

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

Example 1 — Basic $(document).ajaxSend(fn)

Canonical legacy pattern: log when any Ajax request is about to be sent after a click.

jQuery
$(document).ajaxSend(function () {
  $(".log").text("Handler ran via .ajaxSend(function(){ ... }).");
});

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

How It Works

  1. Bind. .ajaxSend(fn) on document registers a global handler.
  2. Delegate. jQuery routes it to .on("ajaxSend", fn) internally.
  3. Click. $.get() starts a qualifying Ajax request.
  4. Send. Just before the HTTP call leaves, the log updates.

Example 2 — Filter by settings.url

Handlers run for every request — narrow them with the settings object.

jQuery
var targetUrl = "https://jsonplaceholder.typicode.com/posts/1";

$(document).ajaxSend(function (event, jqXHR, settings) {
  if (settings.url === targetUrl) {
    $(".log").text("About to send: " + settings.url);
  }
});
Try It Yourself

How It Works

  1. Args. jQuery passes event, jqXHR, and settings.
  2. Compare. Check settings.url against the endpoint you care about.
  3. Act. Update UI or log only for matching URLs.
  4. Skip. Non-matching URLs leave your UI alone.

Example 3 — Append “Starting request at …”

Official-style demo: append a short outbound status for every request about to be sent.

jQuery
$(document).ajaxSend(function (event, request, settings) {
  $("#msg").append(" Starting request at " + settings.url + " ");
});
Try It Yourself

How It Works

  1. Global. One handler covers every qualifying Ajax call.
  2. Append. Each send adds another status fragment with the URL.
  3. Count. Parallel requests each fire their own send event.
  4. Migrate. Swap the bind to .on("ajaxSend") when refactoring.

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

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

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

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

How It Works

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

Example 5 — Remove Handler with .off()

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

jQuery
var count = 0;

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

$(document).ajaxSend(onSend);

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

How It Works

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

Edge Cases & Pitfalls

Watch for these when reading or migrating legacy Ajax code.

deprecated

Do not use in new code

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

target

Bind on document only (1.9+)

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

trigger

No no-arg trigger form

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

timing

No response yet

.ajaxSend() runs before the HTTP call. Do not read responseText here — use ajaxComplete.

Browser Support

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

✓ Deprecated · jQuery 1.0+

jQuery .ajaxSend()

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

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

Performance Notes

ApproachCostBest for
One filtered global handlerCheapSite-wide outbound logging
Per-request beforeSendCheapSetup for a single call
Heavy DOM work every sendExpensiveAvoid — filter or debounce

Legacy and modern binds have the same cost. Keep handlers light, filter by URL before touching the DOM, and prefer beforeSend for request-specific work.

Key Takeaways

  • Role: legacy global “about to send” bind — before the HTTP call.
  • Migrate: $(document).on("ajaxSend", fn) — preferred since 3.5.
  • Args: function(event, jqXHR, ajaxOptions) — filter with ajaxOptions.url.
  • Cleanup: use .off("ajaxSend", fn) — not .unbind().

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

Frequently Asked Questions

The .ajaxSend(handler) method binds a global function that runs just before any qualifying jQuery Ajax request is sent. Attach it to document: $(document).ajaxSend(fn). It is bind-only (no trigger form). Deprecated since jQuery 3.5; use $(document).on("ajaxSend", handler) instead.
Yes. $(document).ajaxSend(handler) has been deprecated since jQuery 3.5 (available since 1.0). Prefer $(document).on("ajaxSend", handler) for new code. Legacy bindings still work in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off("ajaxSend", handler).
ajaxSend is a global Ajax event, not a DOM event on a specific element. Since jQuery 1.9, all global Ajax handlers — including .ajaxSend(handler) — must bind to document. Correct legacy form: $(document).ajaxSend(fn). Modern form: $(document).on("ajaxSend", fn).
The API lists handler as Function(), but the callback receives three arguments — the same as the ajaxSend event: function(event, jqXHR, ajaxOptions). Use ajaxOptions.url to identify the request. The response is not available yet.
Replace $(document).ajaxSend(fn) with $(document).on("ajaxSend", fn). Use $(document).off("ajaxSend", fn) for cleanup instead of .unbind(). Under the hood, .ajaxSend(handler) already delegates to .on("ajaxSend") — migration is a straight rename for simple bindings.
Yes. jQuery 3.x keeps .ajaxSend(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 ajaxSend event tutorial.

Next: ajaxError event

Handle failed Ajax requests with a global document handler.

ajaxError 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