jQuery.ajax() is the core Ajax method (since 1.0; URL+settings form since 1.5). Pass a settings object to send an HTTP request. It returns a jqXHR — chain .done(), .fail(), and .always(). $.get(), $.post(), and .load() are built on top of it.
Remember
$.ajax({
url: "/api/items",
method: "GET", // or type: "GET"
dataType: "json"
}).done(function (data) {
// success
}).fail(function () {
// error
}).always(function () {
// finished either way
});
// Also valid: $.ajax(url, settings)
Use .always() for cleanup that must run either way.
Set global: false when the request should skip document Ajax events.
Call jqXHR.abort() if you need to cancel an in-flight request.
Piece
Required?
Role
url
Yes*
Endpoint (*or set via $.ajaxSetup())
method / type
No
HTTP verb — default "GET"
data
No
Query string (GET) or body (POST)
dataType
No
How to parse the response (json, html, …)
beforeSend
No
Last chance to set headers or return false to cancel
global
No
Default true — set false to skip global events
Pseudocode
Pseudocode
call $.ajax(settings) → returns jqXHR immediately
if beforeSend returns false:
cancel — do not send
if settings.global !== false:
fire ajaxStart (first active) then ajaxSend
send HTTP request asynchronously
when response arrives:
if success:
parse body using dataType
fire ajaxSuccess (if global)
run .done() handlers
else:
fire ajaxError (if global)
run .fail() handlers
fire ajaxComplete (if global)
run .always() handlers
fire ajaxStop when no global requests remain
Reference
Cheat Sheet
Keep these patterns handy while wiring Ajax calls.
Topic
Detail
Signatures
$.ajax(settings) · $.ajax(url, settings)
Returns
jqXHR (XHR + Deferred)
Success
.done(fn) or settings success
Error
.fail(fn) or settings error
Always
.always(fn) or settings complete
Cancel
jqXHR.abort() or beforeSend → false
JSON
dataType: "json"
Silent
global: false
Try it
Live Preview
Run a real $.ajax() call and watch .done() / .fail() update the log.
Live demo uses a public JSON API. Needs network access.
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Basic GET with .done()
Fetch JSON and read a field when the request succeeds.
Global request → ajaxStart runs
Private request (global: false) → silent
.done() / .fail() still work on both
How It Works
Default. Ajax calls participate in global events on document.
Opt out.global: false skips ajaxStart, ajaxSend, and the rest.
Local still works. Per-request .done() / .fail() still run.
When. Use for silent polling or third-party widgets.
Edge Cases & Pitfalls
Check these before shipping Ajax-heavy pages.
async
Avoid async: false
Synchronous Ajax freezes the UI. Using it with Deferred methods is deprecated since 1.8.
parse
Invalid JSON → .fail()
With dataType: "json", a parse error is treated as a failed request — not a successful empty object.
cancel
Cancel with beforeSend or .abort()
Return false from beforeSend to stop before send, or call jqXHR.abort() after.
global
global: false stays silent
Those requests never trigger document Ajax events. Per-request callbacks still work.
Compatibility
Browser Support
jQuery.ajax() has been part of jQuery since 1.0. The $.ajax(url, settings) form and jqXHR Deferred methods (.done() / .fail() / .always()) date from 1.5. Prefer a current jQuery 3.x build.
✓ Stable · jQuery 1.0+
jQuery.ajax()
Works in every browser that runs your loaded jQuery version. Uses XMLHttpRequest under the hood (or a custom transport). Native fetch() is separate and does not trigger jQuery global Ajax events.
100%jQuery Ajax API
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
$.ajax()Universal
Bottom line: Safe for everyday apps. Prefer .done()/.fail()/.always(), keep requests async, and use global: false for silent background calls.
Analysis
Performance Notes
Approach
Cost
Best for
Async $.ajax() (default)
Cheap
Almost all UI work
Shorthands $.get() / $.post()
Same
Simple reads/writes
async: false
Expensive / risky
Avoid — freezes the UI
Keep requests asynchronous, abort obsolete ones when the user navigates away, and avoid heavy DOM work inside every global Ajax handler.
Remember
Key Takeaways
Role: core Ajax API — shorthands like $.get() call it under the hood.
Stay async: avoid async: false; cancel with .abort() when needed.
One line:$.ajax() is jQuery’s full-featured HTTP client — configure settings, then chain the jqXHR.
Frequently Asked Questions
jQuery.ajax() is the core jQuery method for HTTP requests. Pass a settings object (or a URL plus settings) to configure url, method, data, dataType, and more. It returns a jqXHR you can chain with .done(), .fail(), and .always(). Shorthands like $.get() and $.post() call $.ajax() internally.
A jqXHR object — a superset of XMLHttpRequest that also implements the Promise/Deferred interface. Chain .done(fn) for success, .fail(fn) for errors, and .always(fn) for either outcome. Call jqXHR.abort() to cancel an in-flight request.
Both run on success. success is a settings property: $.ajax({ success: fn }). done() is chained on the returned jqXHR: $.ajax(...).done(fn). Prefer done/fail/always — they compose with other Deferreds and match modern promise style.
When global is false, the request opts out of all global Ajax events on document — ajaxStart, ajaxSend, ajaxSuccess, ajaxError, ajaxComplete, and ajaxStop will not fire. Per-request done(), fail(), and always() still run.
Use $.get(url, data, success) for simple GET requests with minimal configuration. Use $.ajax() when you need full control: custom headers, beforeSend, POST with structured data, dataType, global: false, or multiple chained callbacks.
When dataType is "json", jQuery expects JSON and parses the body into a JavaScript value before .done() runs. If parsing fails, the request is treated as an error and .fail() runs. Other common values: "html", "text", "xml", "script".