jQuery ajaxSend Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$(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 });
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 .on("ajaxSend", handler).
Step 2Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3Optionally filter with ajaxOptions.url (or other settings).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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.

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.

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

9 people found this page helpful