jQuery .ajaxSend() Method

Beginner
⚠️ Deprecated since 3.5
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Ajax events

What You’ll Learn

The .ajaxSend() method is jQuery’s legacy shorthand for binding global ajaxSend handlers on document. This tutorial covers $(document).ajaxSend(handler), the handler signature (event, jqXHR, ajaxOptions), why binding must target document since 1.9, migration to .on("ajaxSend") and cleanup with .off("ajaxSend"), and why the method is deprecated since jQuery 3.5. Unlike .click(), there is no trigger variant — only binding. The handler fires before the request is sent. For the modern ajaxSend event API, see the jQuery ajaxSend event tutorial.

01

.ajaxSend(fn)

Bind handler

02

document

Bind target

03

3 args

event, jqXHR, settings

04

Before send

Pre-network hook

05

.on()

Modern bind

06

Deprecated

Since 3.5

Introduction

Before jQuery 1.7 unified events with .on() and .off(), global Ajax events had matching shorthand methods — .ajaxStart(), .ajaxSend(), .ajaxComplete(), and others. The .ajaxSend(handler) method let you register a page-wide “request about to leave” callback in one short call: $(document).ajaxSend(function(){ ... }). It has been available since jQuery 1.0 and remains in jQuery 3.x for backward compatibility but is marked deprecated since 3.5.

Understanding .ajaxSend() matters when reading older admin panels, legacy jQuery plugins, and tutorials written before .on("ajaxSend") became standard. Unlike DOM event shorthands such as .click(), .ajaxSend() has only a binding form — there is no no-argument trigger variant. The handler runs just before the HTTP request is dispatched — ideal for global loading indicators or debug logging. Modern jQuery binds the same global event explicitly: $(document).on("ajaxSend", handler). This page documents the shorthand API and shows how to migrate.

Understanding the .ajaxSend() Method

The official jQuery API describes .ajaxSend() as a way to register a handler to be executed before an Ajax request is sent. When you pass a function, jQuery registers it on document and calls it just before every qualifying Ajax request leaves the browser. That is the same ajaxSend global event that .on("ajaxSend") handles today.

The handler receives three arguments even though the API signature lists only handler: event (the jQuery event object), jqXHR (the XMLHttpRequest wrapper), and ajaxOptions (the settings object passed to $.ajax() — compare ajaxOptions.url to identify the request). Requests with global: false opt out — they do not trigger .ajaxSend() handlers.

⚠️
Deprecated since jQuery 3.5

Do not use $(document).ajaxSend(handler) in new code. Replace it with $(document).on("ajaxSend", handler). Remove handlers with $(document).off("ajaxSend", handler) — not .unbind("ajaxSend"). For event order, URL filtering, global: false, and comparison with the beforeSend option, read the jQuery ajaxSend event tutorial.

📝 Syntax

The .ajaxSend() method has one signature from the official jQuery API — binding only. There is no trigger form unlike .click():

1. Bind a handler — .ajaxSend( handler ) (deprecated since 3.5)

jQuery
$( document ).ajaxSend( handler )
  • handler — function invoked before any qualifying Ajax request is sent. Official docs list Function(); the callback actually receives function( event, jqXHR, ajaxOptions ) { ... }.
  • Must attach to document since jQuery 1.9 — not window or other elements.
  • Fires before the request leaves the browser — after ajaxStart when applicable.
  • Returns the jQuery object (document wrapped) for chaining.
  • Modern replacement: $( document ).on( "ajaxSend", handler ).

2. Official jQuery API migration note

jQuery
// Deprecated binding
$( document ).ajaxSend( function( event, jqXHR, settings ) {
  console.log( "About to send:", settings.url );
} );

// Modern binding
$( document ).on( "ajaxSend", function( event, jqXHR, settings ) {
  console.log( "About to send:", settings.url );
} );

// Remove handler — use .off(), not .unbind()
$( document ).off( "ajaxSend", myHandler );

3. Unbind — $(document).off("ajaxSend" [, handler])

jQuery
$( document ).off( "ajaxSend" );              // remove all ajaxSend handlers
$( document ).off( "ajaxSend", myHandler );   // remove one handler

Do not use deprecated .unbind("ajaxSend") in new code. Store a named function reference when you need to remove a specific handler later.

Return value

  • .ajaxSend(handler) returns the original jQuery object for chaining.
  • Handler return values are ignored by jQuery’s global Ajax event system.

⚡ Quick Reference

GoalLegacy (.ajaxSend)Modern replacement
Bind global send handler$(document).ajaxSend(fn)$(document).on("ajaxSend", fn)
Handler signaturefunction(event, jqXHR, ajaxOptions)
When it firesBefore the HTTP request is sent
Filter by URLif (ajaxOptions.url === "/api/x")
Opt out of global events$.ajax({ url: "/x", global: false })
Remove handlers$(document).off("ajaxSend", fn)
Per-request alternative$.ajax({ beforeSend: fn }) — not global
Trigger ajaxSend programmaticallyNot supported — no no-arg .ajaxSend() trigger form

📋 .ajaxSend() vs .on("ajaxSend") vs beforeSend

Three related APIs — know which one binds globally, which one is modern, and which one is per-request. Unlike .click(), there is no trigger shorthand.

.ajaxSend()
deprecated

Legacy bind — $(document).ajaxSend(fn) — use modern API for new code

.on("ajaxSend")
bind

Modern binding since 1.7 — same behavior, clearer intent, reliable unbinding

beforeSend
per-request

$.ajax({ beforeSend: fn }) — runs only for that one call, not every request on the page

ajaxSend event
concept

Global AjaxEvent — fires before send; full guide on the event tutorial page

Examples Gallery

Five examples cover basic binding, filtering by settings.url, a legacy loading indicator, migration from .ajaxSend() to .on("ajaxSend"), and removing handlers with .off(). Use the Try-it links to run each snippet in the browser. Remember: binding with .ajaxSend(handler) is deprecated — these demos show legacy syntax you will encounter in older code.

📚 Binding & Inspecting

Legacy .ajaxSend() patterns for observing outgoing Ajax requests.

Example 1 — Basic $(document).ajaxSend(fn) + Button Triggers $.get()

The canonical legacy pattern — attach a function on document that runs before any qualifying Ajax request is sent.

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

$(document).ajaxSend(fn) registers the function on document. jQuery internally routes this to .on("ajaxSend", fn). The handler runs before the network call — not after the response arrives.

Example 2 — Filter by settings.url (Legacy Syntax)

All ajaxSend handlers run for every outgoing request — compare settings.url to narrow the callback.

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

Because ajaxSend fires for every global request, URL filtering prevents unrelated endpoints from updating your UI. The settings object is the same ajaxOptions passed to $.ajax().

Example 3 — Legacy Loading Indicator: Show “Sending…” Before Request

A common pattern in older codebases — update a status element before any Ajax request leaves the browser.

jQuery
$( document ).ajaxSend( function() {
  $( "#status" ).text( "Sending request..." );
} );

$( document ).ajaxComplete( function() {
  $( "#status" ).text( "Request finished." );
} );
Try It Yourself

How It Works

ajaxSend is your earliest global hook before the HTTP call. Pair it with ajaxComplete (or migrate both to .on()) to build a minimal page-wide activity indicator without touching every $.ajax() call.

📈 Migration & Cleanup

Compare legacy and modern APIs, and remove handlers with .off().

Example 4 — Migration: .ajaxSend(fn) vs .on("ajaxSend", fn)

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

Under the hood, .ajaxSend(fn) calls .on("ajaxSend", fn). Migration is a straight rename with no behavior change for simple bindings. The modern API also pairs cleanly with .off("ajaxSend", fn) for teardown.

Example 5 — Remove Handler with .off("ajaxSend")

Store a named function reference, 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

Anonymous functions passed to .ajaxSend() cannot be removed individually — use a named function. .off("ajaxSend", onSend) removes exactly that handler. Do not call deprecated .unbind("ajaxSend") in new code.

🚀 Common Use Cases

  • Reading legacy code — recognize $(document).ajaxSend(fn) as equivalent to .on("ajaxSend", fn) in older admin panels.
  • Global loading spinners — legacy pages show “Sending…” via .ajaxSend() — migrate to .on() when refactoring.
  • Debug logging — log outgoing URLs and HTTP methods before requests leave the browser during development.
  • URL filtering — compare settings.url inside .ajaxSend(fn) before updating the DOM.
  • SPA teardown — remove global handlers with .off("ajaxSend", fn) when unmounting a view.
  • Third-party isolation — requests with global: false still opt out of .ajaxSend() handlers.

🧠 How .ajaxSend() Routes Through jQuery

1

You call .ajaxSend(handler)

jQuery treats the function argument as a bind request on document. There is no no-argument trigger form — unlike .click().

bind only
2

Internal delegation

.ajaxSend(handler) delegates internally to .on("ajaxSend", handler) — the handler is stored in jQuery’s event system on document.

.on("ajaxSend")
3

Ajax request is about to send

After ajaxStart (when applicable), jQuery triggers ajaxSend on document — unless the request used global: false.

before network
4

Handler runs with three arguments

function(event, jqXHR, ajaxOptions) — filter by ajaxOptions.url and show loading UI before the response. Returns the jQuery object for chaining.

📝 Notes

  • Deprecated since jQuery 3.5 — do not use $(document).ajaxSend(handler) in new code. Use .on("ajaxSend") instead. Available since jQuery 1.0.
  • Attach to document since jQuery 1.9 — not window or other elements.
  • Binding only — no no-argument trigger form unlike .click() or .mousedown().
  • Handler receives (event, jqXHR, ajaxOptions) even though the API lists handler as Function().
  • Fires before the request is sent — not after the response arrives (ajaxComplete handles that).
  • Remove handlers with $(document).off("ajaxSend", handler) — not .unbind("ajaxSend").
  • Requests with global: false do not trigger .ajaxSend() handlers.
  • For per-request setup, use the beforeSend option in $.ajax() instead of a global handler.
  • Legacy code using .ajaxSend() still runs in jQuery 3.x — migrate when you refactor those files.
  • For event order, comparison with beforeSend, and the complete modern workflow, see the jQuery ajaxSend event tutorial.

Browser Support

The underlying ajaxSend global event works wherever jQuery’s Ajax transport runs. The .ajaxSend() method itself is a jQuery API — it works in jQuery 1.x, 2.x, and 3.x when bound to document since 1.9. Binding via .ajaxSend(handler) is deprecated since 3.5 but still functional.

jQuery 1.0+

jQuery .ajaxSend() method

Supported across all jQuery versions you are likely to maintain. Deprecated binding since 3.5 — use .on('ajaxSend') for new projects. Requires jQuery Ajax — 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.

Conclusion

The jQuery .ajaxSend() method is the legacy shorthand for binding global Ajax send handlers on document. Use $(document).ajaxSend(handler) to register a callback — deprecated since jQuery 3.5. The handler receives (event, jqXHR, ajaxOptions) and runs just before every qualifying request leaves the browser.

For new code, prefer $(document).on("ajaxSend", fn) for binding and $(document).off("ajaxSend", fn) for cleanup. When you encounter .ajaxSend() in older projects, recognize it, understand it, and migrate when practical. For the full modern ajaxSend workflow — event order, URL filtering, and global: false — continue with the jQuery ajaxSend event tutorial, then learn ajaxError for the global error hook.

💡 Best Practices

✅ Do

  • Use $(document).on("ajaxSend", handler) for all new global bindings
  • Bind on document — required since jQuery 1.9
  • Store named function references when you need to remove handlers later
  • Remove handlers with $(document).off("ajaxSend", fn) on SPA teardown
  • Read the modern ajaxSend event tutorial for full API coverage

❌ Don’t

  • Write new code with deprecated $(document).ajaxSend(handler)
  • Attach global handlers to window — use document
  • Expect a no-arg .ajaxSend() trigger form — it does not exist
  • Use .unbind("ajaxSend") — it is also deprecated; use .off()
  • Confuse .ajaxSend() with beforeSend — one is global, one is per-request

Key Takeaways

Knowledge Unlocked

Six things to remember about .ajaxSend()

Legacy bind, modern migrate.

6
Core concepts
doc 02

document

Bind here

Since 1.9
03

3 args

event, jqXHR, settings

Handler
.on 04

.on("ajaxSend")

Modern

Replace
.off 05

.off()

Remove

Cleanup
3.5 06

Deprecated

Since 3.5

Migrate

❓ Frequently Asked Questions

The .ajaxSend(handler) method binds a global function that runs just before any qualifying jQuery Ajax request is sent over the network. You must attach it to document: $(document).ajaxSend(fn). Unlike .click(), there is no no-argument trigger form — only binding. The method has been deprecated since jQuery 3.5; use $(document).on('ajaxSend', handler) instead.
Yes — $(document).ajaxSend(handler) is deprecated since jQuery 3.5 (available since jQuery 1.0). Use $(document).on('ajaxSend', handler) for new code. Existing legacy code continues to run in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off('ajaxSend', handler), not the deprecated .unbind() API.
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 be bound to document, not window or other elements. The correct legacy pattern is $(document).ajaxSend(fn); the modern equivalent is $(document).on('ajaxSend', fn).
The official jQuery API lists handler as Type Function(), but the callback actually receives three arguments — the same as the ajaxSend event: function(event, jqXHR, ajaxOptions). Use ajaxOptions.url and ajaxOptions.type to identify which request is about to leave the browser.
Replace $(document).ajaxSend(fn) with $(document).on('ajaxSend', fn). Replace cleanup via .unbind('ajaxSend') with $(document).off('ajaxSend', fn). Under the hood, .ajaxSend(handler) already delegates to .on('ajaxSend') — migration is a straight rename with no behavior change for simple bindings.
.ajaxSend() is a global document shorthand — one handler observes every qualifying request on the page. beforeSend is a per-request option in $.ajax(settings) — it runs only for that single call. Use global .ajaxSend() (or .on('ajaxSend')) for site-wide logging or spinners; use beforeSend for request-specific setup.
Did you know?

Unlike DOM event shorthands such as .click(), which support both binding (.click(fn)) and triggering (no-arg .click()), .ajaxSend() is bind-only. You cannot programmatically fire global Ajax events through a no-argument .ajaxSend() call — they fire automatically when jQuery’s Ajax transport is about to send a request. The deprecated method is simply sugar for .on("ajaxSend", fn) on document. For a single request, the beforeSend option in $.ajax() runs at the same lifecycle point but only for that call.

Next: ajaxError Event

Learn the global handler that runs when Ajax requests fail.

ajaxError event 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.

6 people found this page helpful