The ajaxSend event fires just before any qualifying jQuery Ajax request is sent. This tutorial covers binding on document with .on("ajaxSend"), the handler signature (event, jqXHR, ajaxOptions), filtering by ajaxOptions.url, opting out with global: false, and comparing global ajaxSend with per-request beforeSend and post-finish ajaxComplete.
01
Global
AjaxEvent
02
document
Bind target
03
Before send
Not after
04
settings
Filter URL
05
global:false
Opt out
06
Since 1.7
.on() API
Fundamentals
Introduction
When your page loads data with $.ajax(), $.get(), $.post(), or .load(), jQuery broadcasts lifecycle events to listeners on document. The ajaxSend event is your “about to go out” hook — it fires immediately before the HTTP request is sent, giving you a last chance to log, validate, or adjust headers globally.
The official jQuery API distinguishes the ajaxSendevent (bound with .on("ajaxSend") since 1.7) from the deprecated .ajaxSend()method used in older code. Unlike ajaxComplete, which runs after the response returns, ajaxSend runs at the start of the pipeline — and all registered handlers execute for every qualifying outgoing request.
Concept
Understanding the ajaxSend Event
ajaxSend is classified as an AjaxEvent — a global event triggered by jQuery’s Ajax transport, not a DOM event on a specific element. Whenever an Ajax request is about to be sent, jQuery triggers ajaxSend on document. Handlers receive three arguments: the native event object, the jqXHR object (the XMLHttpRequest wrapper returned by $.ajax()), and ajaxOptions — the plain settings object used to create that request.
The handler runs before the network call leaves the browser — after ajaxStart (when this is the first active global request) but before ajaxSuccess, ajaxError, or ajaxComplete. To react only to certain URLs, inspect ajaxOptions.url inside the handler. At this stage the response is not available yet; use ajaxComplete if you need jqXHR.responseText.
💡
Beginner Tip
Bind once on $(document).on("ajaxSend", fn) instead of adding a beforeSend callback to every $.ajax() call. Use global: false on requests that should not notify global listeners — for example, background polling or third-party widgets.
Foundation
📝 Syntax
The modern jQuery API for the ajaxSend global event:
1. Bind a handler — $(document).on("ajaxSend" [, handler]) (since 1.7)
jQuery
$( document ).on( "ajaxSend", handler )
handler — function invoked before any qualifying Ajax request is sent: function( event, jqXHR, ajaxOptions ) { ... }.
event — the jQuery event object.
jqXHR — the jqXHR / XMLHttpRequest object for this request.
The old .ajaxSend(handler) binding method still works but is deprecated. Migrate to $(document).on("ajaxSend", handler) for consistency with other events and reliable unbinding via .off().
Return value
.on("ajaxSend", handler) returns the jQuery object (document wrapped) for chaining.
Handler return values are ignored by jQuery’s global Ajax event system.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind global send handler
$(document).on("ajaxSend", fn)
Handler signature
function(event, jqXHR, ajaxOptions)
When it fires
Before request is sent (not after completion)
Filter by URL
if (ajaxOptions.url === "/api/x")
Opt out of global events
$.ajax({ url: "/x", global: false })
Per-request setup
$.ajax({ beforeSend: fn })
Remove handlers
$(document).off("ajaxSend")
Compare
📋 ajaxSend vs ajaxComplete vs beforeSend
Three ways to hook into Ajax request timing — choose the scope and moment that match your task.
ajaxSend
global
Document event — runs for every qualifying request, before it is sent
ajaxComplete
global
Document event — runs after the request finishes, success or error
beforeSend
per call
$.ajax() option — runs once for a single request before send
ajaxStart
global
Document event — first active global request begins (before ajaxSend)
Global event order for each request: ajaxStart → ajaxSend → ajaxSuccess | ajaxError → ajaxComplete → ajaxStop. ajaxStart and ajaxStop bracket the set of active global requests — they fire when the first request begins and when the last one finishes.
Hands-On
Examples Gallery
Examples 1, 3, and 4 follow the official jQuery API documentation. Examples 2 and 5 extend those patterns with URL filtering and a comparison with ajaxComplete. Use the Try-it links to run each snippet in the browser.
📚 Official Patterns
Document-level handlers that observe every qualifying Ajax request before it is sent.
Example 1 — Official Demo: Document Handler + .load() on Click
Attach ajaxSend on document, then trigger an Ajax request with .load() when the user clicks .trigger. The log updates before the request is sent.
User clicks .trigger → ajaxSend fires → .log shows "Triggered ajaxSend handler."
Then .load() sends the HTTP request and loads HTML into .result
Works for $.ajax(), $.get(), $.post(), and .load()
How It Works
.load() is implemented with $.ajax() internally, so it triggers global Ajax events. The ajaxSend handler on document runs immediately before the request leaves the browser — before any response arrives.
Example 2 — Filter by settings.url
All ajaxSend handlers run for every request — use ajaxOptions.url to narrow the callback to one endpoint.
Request to ajax/test.html about to send → .log shows handler message
Request to other URLs → handler runs but if-block skipped
Use settings.type, settings.context, or custom keys to filter further
How It Works
jQuery passes the same settings object used in $.ajax(settings) as the third argument. Compare settings.url (or a custom property you add to settings) before updating the DOM or logging.
Example 3 — Official Demo: Append “Starting request at” to #msg
Show a message in the page whenever any Ajax request is about to be sent.
Each qualifying Ajax request → #msg gains " Starting request at URL "
Three parallel requests → three appended messages before responses return
Ideal for a simple activity log or debug strip
How It Works
Because ajaxSend fires for every global request before send, appending to #msg builds a running outbound log. Pair with URL filtering if you only want messages for specific endpoints.
📈 Opt-Out & Lifecycle Comparison
global: false and comparing ajaxSend with ajaxComplete on the same page.
Example 4 — global: false — Event Does Not Fire
Requests with global: false skip all global Ajax events, including ajaxSend.
Click #global-btn → ajaxSend fires → log updated before request sends
Click #private-btn → request sends but ajaxSend does NOT fire
Per-request beforeSend on the private call still runs
How It Works
Setting global: false on an individual $.ajax() call (or via $.ajaxSetup({ global: false })) opts that request out of ajaxStart, ajaxSend, ajaxSuccess, ajaxError, ajaxComplete, and ajaxStop.
Example 5 — Compare Global ajaxSend Counter vs ajaxComplete Counter
Track outbound requests with ajaxSend (before send) and finished requests with ajaxComplete (after response) on the same page.
Click #run-two → two $.ajax() calls
sendCount → +2 (ajaxSend before each request leaves)
completeCount → +2 (ajaxComplete after each response)
Event order per request: ajaxSend → … → ajaxComplete
How It Works
ajaxSend is ideal for outbound logging, request tokens, or last-chance header tweaks. ajaxComplete is ideal for cleanup after the response — hide spinners, parse results, etc. Both counters increment by the same amount, but at different points in the lifecycle.
Applications
🚀 Common Use Cases
Outbound logging — append “Starting request at URL” to a debug panel before each Ajax call during development.
Global headers — set CSRF tokens or auth headers in an ajaxSend handler (or prefer $.ajaxSetup / beforeSend for clearer intent).
Request counting — track in-flight outbound requests alongside ajaxComplete for a full send/finish picture.
Analytics hooks — record request start time and URL when ajaxSend fires, filtered by settings.url.
Third-party isolation — set global: false on widget requests so they do not trigger your global ajaxSend logic.
Testing — assert that a test harness saw the expected number of outgoing requests via a global counter.
🧠 Global Ajax Event Order
1
ajaxStart
First active global request begins — show a page-wide loading indicator.
ajaxStart
2
ajaxSend
Just before the request is sent — all registered ajaxSend handlers execute.
ajaxSend
3
ajaxSuccess or ajaxError
Outcome-specific global event — success handler or error handler runs.
success | error
4
ajaxComplete
Always runs after step 3 — request finished, success or error.
ajaxComplete
5
👉
ajaxStop
Last active global request finished — hide the loading indicator.
Important
📝 Notes
Bind with $(document).on("ajaxSend", handler) since jQuery 1.7 — not the deprecated .ajaxSend(handler) method.
Since jQuery 1.9, attach global Ajax handlers to document — not window.
ajaxSend fires before the request is sent — not after completion like ajaxComplete.
Every registered handler runs for every qualifying outgoing request.
Requests with global: false do not trigger ajaxSend.
The response body is not available in ajaxSend — use ajaxComplete for jqXHR.responseText.
Differentiate requests with ajaxOptions.url, ajaxOptions.type, or custom settings properties.
For per-request setup, prefer beforeSend in $.ajax(settings) over a global handler with heavy filtering.
Compatibility
Browser Support
The ajaxSend event is a jQuery global Ajax event — not a native DOM event. It works wherever jQuery’s Ajax transport runs: all browsers supported by your jQuery version. Bind with .on("ajaxSend") since 1.7; attach handlers to document since 1.9.
✓ jQuery 1.7+
jQuery ajaxSend event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Requires jQuery Ajax — requests made with fetch() or axios do not trigger jQuery global events.
100%With jQuery Ajax
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
ajaxSendUniversal
Bottom line: Safe in any jQuery project using $.ajax(), $.get(), $.post(), or .load(). Prefer .on('ajaxSend') over deprecated .ajaxSend().
Wrap Up
Conclusion
The jQuery ajaxSend event is the global “request about to go out” hook — it runs before every qualifying Ajax call leaves the browser. Bind handlers on document with .on("ajaxSend", fn), inspect ajaxOptions to filter by URL, and remember that the response is not available yet at this stage.
Remember the event order: ajaxStart → ajaxSend → ajaxSuccess or ajaxError → ajaxComplete → ajaxStop. Use global: false to opt out. For logic tied to one call, use the beforeSend option on that $.ajax() instead of growing a global handler.
Filter with ajaxOptions.url when the handler should not run for every request
Pair with ajaxComplete for a full send-to-finish lifecycle log
Use global: false for silent background or third-party requests
Remove handlers with $(document).off("ajaxSend") on SPA teardown
❌ Don’t
Attach global handlers to window — use document since jQuery 1.9
Use deprecated .ajaxSend(handler) in new code
Expect responseText in ajaxSend — the response has not arrived yet
Block or cancel requests inside ajaxSend — use beforeSend returning false instead
Duplicate per-request beforeSend logic inside a global handler without filtering
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about ajaxSend
Global, before send, on document.
6
Core concepts
doc01
document
Bind here
Global
→02
Before send
Not after
Timing
url03
settings
Filter
ajaxOptions
bs04
beforeSend
Per request
Option
off05
global:false
Opt out
Private
.on06
.on()
Not .ajaxSend()
Modern
❓ Frequently Asked Questions
ajaxSend is a global Ajax event (AjaxEvent) that fires just before any qualifying jQuery Ajax request is sent over the network. Bind handlers with $(document).on('ajaxSend', handler) since version 1.7. Every registered handler runs for every outgoing request.
Since jQuery 1.9, all global Ajax event handlers — including ajaxSend — must be bound to document, not window or other elements. Use $(document).on('ajaxSend', fn) and $(document).off('ajaxSend', fn) to remove them.
ajaxSend fires before the request leaves the browser — it is your last global hook before the HTTP call. ajaxComplete fires after the request finishes, whether it succeeded or failed. For each request: ajaxStart → ajaxSend → (response) → ajaxSuccess|ajaxError → ajaxComplete → ajaxStop.
ajaxSend is a global document event — 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 for site-wide logging or headers; use beforeSend for request-specific setup.
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() callbacks still run normally.
Inspect the handler arguments: function(event, jqXHR, ajaxOptions). The ajaxOptions object is the settings used to create the request — compare ajaxOptions.url, ajaxOptions.type, or a custom ajaxOptions.context to filter handlers to specific calls.
Did you know?
jQuery fires ajaxSend for every registered handler — if three functions listen on document, all three run before one request is sent. That differs from per-request beforeSend, which runs only for the call that defines it. The deprecated .ajaxSend(fn) method is equivalent to .on("ajaxSend", fn); jQuery 1.7 unified binding under .on() alongside mouse and keyboard events.