jQuery Ajax Events

What You’ll Learn
Global Ajax events let you observe every jQuery request from one place on document. Bind ajaxComplete for finish notifications, ajaxStart and ajaxStop for loading indicators, and use global: false when a call should stay private.
ajaxStart
First request
ajaxSend
Before send
ajaxSuccess
2xx response
ajaxComplete
Always runs
global:false
Opt out
24 guides
Full index
Introduction
When your app loads data with $.ajax(), $.get(), or $.post(), jQuery can broadcast lifecycle events to every listener on the page. Global handlers are ideal for spinners, request logging, and shared error toasts — without copying the same callback onto dozens of individual calls.
What Are jQuery Global Ajax Events?
Global Ajax events are named strings passed to $(document).on() — "ajaxStart", "ajaxSend", "ajaxSuccess", "ajaxError", "ajaxComplete", and "ajaxStop". Each handler receives the native event plus jQuery-specific arguments such as the jqXHR object and request settings. They fire only for requests where global is not set to false.
Bind global handlers on document with .on("ajaxComplete", fn), .on("ajaxStart", fn), and the other global event names — since jQuery 1.9, $(document) is the supported target for all global Ajax events.
📝 Syntax
Minimal global handler workflow:
$(document).on("ajaxStart", function() {
$("#spinner").show();
});
$(document).on("ajaxComplete", function(event, xhr, settings) {
console.log("Finished:", settings.url);
});
$(document).on("ajaxStop", function() {
$("#spinner").hide();
});
$.ajax({ url: "/api/ping", global: false }); 👀 ajaxComplete vs always() vs global:false
Three ways to react when a request finishes — pick the right tool:
Ajax Event Tutorial Index
Search by event name or browse by category. Each tutorial includes syntax, try-it examples, and FAQs.
Core Ajax API
4 tutorialsMake HTTP requests with jQuery.ajax() — the foundation behind $.get(), $.post(), and .load().
| Event | Description | Tutorial |
|---|---|---|
jQuery.ajax() method | Core Ajax API — configure HTTP requests with a settings object and chain done(), fail(), and always() on jqXHR. | Open |
jQuery.ajaxPrefilter() method | Register global hooks that modify Ajax options before each request is sent — custom defaults, abort-on-retry, and dataType filters. | Open |
jQuery.ajaxSetup() method | Set default Ajax options for every future request — jQuery recommends explicit per-call options or a wrapper instead. | Open |
jQuery.ajaxTransport() method | Register custom transport factories with send() and abort() — last resort for non-standard dataTypes and protocols. | Open |
Ajax Shorthands
5 tutorialsReadable one-liners built on $.ajax() — GET, POST, and JSON helpers.
| Event | Description | Tutorial |
|---|---|---|
jQuery.get() method | GET shorthand for $.ajax() — load data with url, optional query data, success callback, and dataType in one line. | Open |
jQuery.post() method | POST shorthand for $.ajax() — send data in the request body with url, data, success callback, and dataType in one line. | Open |
jQuery.getJSON() method | GET JSON shorthand — dataType json is preset so success callbacks receive a parsed object or array. | Open |
jQuery.getScript() method | GET script shorthand — load and execute JavaScript files with dataType script preset and cache busting by default. | Open |
jQuery .load() method | Collection method — fetch HTML from a URL and inject it into matched elements, with optional fragment selector. | Open |
Ajax Utilities
3 tutorialsSerialize data for URLs and request bodies — the helper behind $.serialize() and manual query building.
| Event | Description | Tutorial |
|---|---|---|
jQuery.param() method | Serialize plain objects, arrays, and form data into URL-encoded query strings for Ajax requests and GET URLs. | Open |
jQuery .serialize() method | Encode successful form controls as a URL query string — ready for $.post() and Ajax form submission. | Open |
jQuery .serializeArray() method | Encode form controls as an array of name/value objects — iterate, transform, then pass to $.param(). | Open |
Global Ajax Events
12 tutorialsObserve every Ajax request on the page from a single document handler.
| Event | Description | Tutorial |
|---|---|---|
ajaxStart event | Register a document-level handler when the first global Ajax request begins — pair with ajaxStop for loading UI. | Open |
.ajaxStart() method | Deprecated shorthand for binding global ajaxStart handlers on document — migrate to .on('ajaxStart'). | Open |
ajaxSend event | Register a document-level handler that runs before any global Ajax request is sent. | Open |
.ajaxSend() method | Deprecated shorthand for binding global ajaxSend handlers on document — migrate to .on('ajaxSend'). | Open |
ajaxError event | Register a document-level handler that runs when any global Ajax request completes with an error. | Open |
.ajaxError() method | Deprecated shorthand for binding global ajaxError handlers on document — migrate to .on('ajaxError'). | Open |
ajaxSuccess event | Register a document-level handler when any global Ajax request completes successfully. | Open |
.ajaxSuccess() method | Deprecated shorthand for binding global ajaxSuccess handlers on document — migrate to .on('ajaxSuccess'). | Open |
ajaxComplete event | Register a document-level handler that runs when any global Ajax request finishes — success or error. | Open |
.ajaxComplete() method | Deprecated shorthand for binding global ajaxComplete handlers on document — migrate to .on('ajaxComplete'). | Open |
ajaxStop event | Register a document-level handler when the last global Ajax request completes — pair with ajaxStart for loading UI. | Open |
.ajaxStop() method | Deprecated shorthand for binding global ajaxStop handlers on document — migrate to .on('ajaxStop'). | Open |
Conclusion
jQuery global Ajax events centralize request lifecycle handling on document. Bind ajaxStart and ajaxStop for loading UI, listen to ajaxComplete when you need a hook that runs on success or failure, and set global: false on calls that should stay invisible to the rest of the page.
❓ Frequently Asked Questions
Start with jQuery.ajax()
Learn the core Ajax API — settings, jqXHR, and promise-style callbacks — before global events.
6 people found this page helpful
