jQuery .ajaxSend() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.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 })
CallWhat it does
documentOnly valid bind target for global Ajax events
handlerfunction(event, jqXHR, ajaxOptions)
ajaxOptions.urlFilter which requests you react to
global: falseSkip 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

ParameterDescription
Step 1Attach the handler to document with .ajaxSend(handler) (legacy) or .on("ajaxSend", handler) (preferred).
Step 2Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3Optionally filter with ajaxOptions.url (response is not available yet).

Return Value

Return ValueDescription
jQuery objectMost 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");
});
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.

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.

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.

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 Event tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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