jQuery ajaxSend Event

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

What Is ajaxSend?

ajaxSend is a global AjaxEvent (since jQuery 1.0; .on() binding since 1.7). jQuery triggers it on document just before any qualifying Ajax request is sent. All registered handlers run.

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

// Order (per request):
// ajaxStart → ajaxSend → (response) → ajaxSuccess|ajaxError → ajaxComplete

// Opt out for one call:
$.ajax({ url: "/x", global: false });
NeedUse
Global “about to send”$(document).on("ajaxSend", fn)
One request only$.ajax({ beforeSend: fn })
After request finishesajaxComplete
First active requestajaxStart
Hide loading when idleajaxStop

How to Use ajaxSend

Bind once on document, then any jQuery Ajax call can notify that handler before it leaves.

  1. Attach the handler to document with .on("ajaxSend", handler).
  2. Make requests with $.ajax(), $.get(), $.post(), or .load().
  3. Optionally filter with ajaxOptions.url (or other settings).
  4. Use global: false on requests that must stay silent.
  5. Prefer beforeSend when logic belongs to one call only.
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
bind ajaxSend on document with handler(event, jqXHR, ajaxOptions)

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

    if this is the first active global request:
        fire ajaxStart

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

    send the HTTP request
    // response is not available yet — use ajaxComplete later

Cheat Sheet

Keep these facts handy while wiring global Ajax send hooks.

TopicDetail
Bind$(document).on("ajaxSend", handler)
Unbind$(document).off("ajaxSend" [, handler])
Signaturefunction(event, jqXHR, ajaxOptions)
WhenJust before each qualifying request is sent
SinceEvent 1.0 · .on() form 1.7 · document-only 1.9+
Response bodyNot available yet — use ajaxComplete
Filterif (ajaxOptions.url === "...")
Opt outglobal: false in $.ajax() / $.ajaxSetup()

Live Preview

Run a real $.get() and watch the global ajaxSend handler update the log before the request leaves.

Live demo uses a public JSON API. Needs network access.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Document Handler + .load()

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

jQuery
$(document).on("ajaxSend", function () {
  $(".log").text("Triggered ajaxSend handler.");
});

$(".trigger").on("click", function () {
  $(".result").load("ajax/test.html");
});
Try It Yourself

How It Works

  1. Bind. .on("ajaxSend") on document listens globally.
  2. Click. .load() starts an Ajax request under the hood.
  3. Send. Just before the HTTP call leaves, every ajaxSend handler runs.
  4. Update. The log text confirms the global event fired — response comes later.

Example 2 — Filter by settings.url

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

jQuery
$(document).on("ajaxSend", function (event, jqxhr, settings) {
  if (settings.url === "ajax/test.html") {
    $(".log").text("Triggered ajaxSend handler.");
  }
});
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 demo: append a short outbound status for every request about to be sent.

jQuery
$(document).on("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 ajaxSend.
  4. Use. Handy for a simple outbound activity strip or debug log.

Example 4 — Opt Out with global: false

Private requests skip all global Ajax events, including ajaxSend.

jQuery
$(document).on("ajaxSend", function () {
  $("#log").append(" ajaxSend");
});

// Fires ajaxSend
$.get("/api/public");

// Does NOT fire ajaxSend
$.ajax({ url: "/api/silent", global: false });
Try It Yourself

How It Works

  1. Default. Ajax calls participate in global events.
  2. Opt out. global: false skips ajaxSend (and the other globals).
  3. Local still works. beforeSend / .done() / .fail() still run.
  4. When. Use for silent prefetch, polling, or third-party widgets.

Example 5 — ajaxSend vs beforeSend

Global event sees every request; beforeSend is tied to one call.

jQuery
var globalCount = 0;
var localCount = 0;

$(document).on("ajaxSend", function () {
  globalCount++;
});

$.ajax({
  url: "/a",
  beforeSend: function () { localCount++; }
});
$.ajax({
  url: "/b",
  beforeSend: function () { localCount++; }
});

// After both start sending:
// globalCount === 2, localCount === 2
// but each beforeSend only saw its own request
Try It Yourself

How It Works

  1. Global. One ajaxSend handler counts every outgoing request.
  2. Local. Each beforeSend only increments for its own call.
  3. Same totals. Counts can match, but the scope is different.
  4. Choose. Site-wide logging → global event; one call’s setup (or cancel) → beforeSend.

Edge Cases & Pitfalls

Check these before relying on global Ajax send handlers in production.

target

Bind on document only (1.9+)

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

timing

No response yet

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

cancel

Cannot cancel from ajaxSend

Return false from per-request beforeSend to abort. Global ajaxSend is for observation, not cancellation.

global

global: false stays silent

Those requests never trigger ajaxSend. Per-request callbacks still work.

Browser Support

ajaxSend has been part of jQuery since 1.0. Prefer $(document).on("ajaxSend", …) (1.7+). Since 1.9, handlers must attach to document.

✓ Stable · jQuery 1.0+

jQuery ajaxSend

Works in every browser that runs your loaded jQuery version. Prefer a current jQuery 3.x build for modern projects.

100% jQuery Ajax event
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 Universal

Bottom line: Safe for everyday apps. Bind on document, filter by URL when needed, and use global: false for silent background calls.

Performance Notes

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

Global handlers are fine when they stay light. Filter by URL before touching the DOM, and prefer beforeSend for request-specific work.

Key Takeaways

  • Role: global “request about to leave” hook — before the HTTP call.
  • Bind: $(document).on("ajaxSend", fn) — document only since 1.9.
  • Filter: inspect ajaxOptions.url; response is not available yet.
  • Local alternative: use beforeSend for one-request setup or cancel.

One line: ajaxSend is jQuery’s global before-send Ajax event — bind it on document.

Frequently Asked Questions

ajaxSend is a global AjaxEvent that fires just before any qualifying jQuery Ajax request is sent. Bind it with $(document).on("ajaxSend", handler) (since 1.7). Every registered handler runs for every outgoing request.
Since jQuery 1.9, all global Ajax event handlers must be bound to document — not window or other elements. Use $(document).on("ajaxSend", fn) and remove with $(document).off("ajaxSend", fn).
ajaxSend fires before the request leaves the browser. ajaxComplete fires after it finishes (success or error). Order: ajaxStart → ajaxSend → (response) → ajaxSuccess|ajaxError → ajaxComplete → ajaxStop.
ajaxSend is a global document event — one handler observes every qualifying request. beforeSend is a per-request $.ajax() option — it runs only for that call. Use ajaxSend for site-wide logging; use beforeSend for one-call setup (and to cancel by returning false).
When $.ajax() or $.ajaxSetup() sets global: false, that request opts out of all global Ajax events. ajaxSend will not fire for it. Per-request beforeSend, done(), fail(), and always() still run.
Three: function(event, jqXHR, ajaxOptions). event is the jQuery event; jqXHR is the request object; ajaxOptions is the settings used to create the request (filter with ajaxOptions.url). The response is not available yet.
The shorthand method .ajaxSend(handler) is deprecated as of jQuery 3.5. Prefer $(document).on("ajaxSend", handler) — the event API this page teaches.

Next: .ajaxSend() method

See the deprecated shorthand and how to migrate to .on("ajaxSend").

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

9 people found this page helpful