.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).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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 })
Call
What it does
document
Only valid bind target for global Ajax events
handler
function(event, jqXHR, ajaxOptions)
ajaxOptions.url
Filter which requests you react to
global: false
Skip 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
Parameter
Description
Step 1
Attach the handler to document with .ajaxSend(handler) (legacy) or .on("ajaxSend", handler) (preferred).
Step 2
Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3
Optionally filter with ajaxOptions.url (response is not available yet).
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
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");
});
Each outgoing request →
#msg gains " Starting request at URL "
Three parallel calls → three appends before responses
How It Works
Global. One handler covers every qualifying Ajax call.
Append. Each send adds another status fragment with the URL.
Count. Parallel requests each fire their own send event.
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.