jQuery.ajaxSetup(options) (since 1.1) sets default Ajax options merged into every future $.ajax(), $.get(), $.post(), and .load() call until the next setup. It returns a PlainObject of merged ajaxSettings.
Remember
$.ajaxSetup({ url: "ping.php" });
// url omitted → uses ping.php from setup
$.ajax({ data: { name: "Dan" } });
// Per-call options override setup
// Do NOT put success/error/complete in ajaxSetup
// Prefer $(document).on("ajaxSuccess", …) instead
Call once at bootstrap if you must — then every Ajax helper inherits those defaults.
Pass a PlainObject of the same keys as $.ajax() (url, type, dataType, global, …).
Later Ajax calls merge those defaults automatically.
Override any key on a single call by passing it explicitly.
Bind global callbacks with $(document).on("ajaxSuccess") — not inside setup.
For new code, skip setup and use a wrapper or explicit options instead.
Piece
Required?
Role
options
Yes
Default key/value pairs (same as $.ajax())
Return value
—
Merged ajaxSettings PlainObject
Per-call options
Optional
Override matching setup keys for that request
Next $.ajaxSetup()
—
Merges new keys into ajaxSettings
Pseudocode
Pseudocode
$.ajaxSetup(defaults)
store defaults into jQuery.ajaxSettings
return merged ajaxSettings
when $.ajax / $.get / $.post / .load runs:
settings = merge(ajaxSettings, callerOptions)
// callerOptions win on conflicts
run ajaxPrefilter handlers on settings
send request with settings
Reference
Cheat Sheet
Keep these facts handy when reading or refactoring legacy Ajax setup.
Topic
Detail
Call
$.ajaxSetup({ url, type, dataType, global, … })
Affects
$.ajax, $.get, $.post, .load
Override
Pass the same key on the individual request
Since
jQuery 1.1
Return
PlainObject (ajaxSettings)
Callbacks
Use $(document).on("ajaxSuccess|ajaxError|ajaxComplete")
Pipeline
Setup merge → prefilters → beforeSend → send
Safer alt
Wrapper function with explicit $.ajax({ … })
Try it
Live Preview
Apply a temporary dataType: "json" default, then run a bare $.get() that inherits it.
Demo uses a public JSON API. Needs network access. Setup is applied only for this widget.
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 — Default url
Official idea: set a base URL once, then omit url on later calls.
jQuery
$.ajaxSetup({
url: "https://jsonplaceholder.typicode.com/posts/1",
dataType: "json"
});
$("#load").on("click", function () {
// url not set here — uses ajaxSetup default
$.ajax({
data: { _: Date.now() }
}).done(function (post) {
$("#result").text("Loaded: " + post.title);
});
});
apiGet("/users/1") uses wrapper defaults
Plugins using raw $.get() stay unaffected
#out shows the user email
How It Works
Scope. Defaults live inside apiGet, not global setup.
Call. Your code uses the helper; plugins still use normal jQuery defaults.
Explicit. Each request still goes through $.ajax() with clear options.
Prefer. This is the pattern jQuery recommends instead of $.ajaxSetup().
Edge Cases & Pitfalls
Check these before relying on global Ajax defaults.
plugins
Affects every Ajax caller
Third-party widgets and analytics may inherit your URL, method, or headers unexpectedly.
callbacks
No success/error in setup
Global response handlers belong on $(document).on("ajaxSuccess") (and related events), not in the setup object.
merge
Setup merges into ajaxSettings
Each $.ajaxSetup() call updates matching keys in shared defaults — unset keys keep their previous values.
global
global: false is site-wide
As a setup default it silences Ajax events for every inheriting request, including ones you did not write.
Compatibility
Browser Support
jQuery.ajaxSetup() has been part of jQuery since 1.1. It works wherever your loaded jQuery Ajax transport runs.
✓ Stable · jQuery 1.1+
jQuery.ajaxSetup()
Supported across jQuery 1.x, 2.x, and 3.x in every browser that runs your jQuery build. Prefer current jQuery 3.x for modern projects — and prefer wrappers over global setup.
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
$.ajaxSetup()Universal
Bottom line: Technically available everywhere jQuery Ajax works. Architecturally risky on plugin-heavy pages — prefer explicit options or a scoped helper.
Analysis
Performance Notes
Approach
Cost
Best for
Explicit $.ajax({ … })
Cheap
Clear, safe call sites
Small wrapper helper
Cheap
Shared defaults you control
$.ajaxSetup()
Cheap CPU · high risk
Legacy only — avoid in new code
$.ajaxPrefilter()
Cheap
Conditional per-request logic
Setup itself is inexpensive. The cost is correctness: hidden global state is harder to reason about than a small helper or explicit options.
Remember
Key Takeaways
Role: merges default Ajax options into future requests.
Override: per-call options always win for that request.
Events: bind globals with .on("ajaxSuccess") — not setup callbacks.
Prefer: a scoped wrapper over mutating shared ajaxSettings.
One line:$.ajaxSetup() sets page-wide Ajax defaults — useful to understand in legacy code, risky to rely on in new code.
Frequently Asked Questions
It sets default option values that jQuery merges into every future Ajax request — including $.ajax(), $.get(), $.post(), and .load() — until the next $.ajaxSetup() call. It returns a PlainObject of the merged ajaxSettings. Per-call options override matching defaults.
Global defaults affect every Ajax caller on the page, including plugins that expect jQuery’s normal defaults. A plugin’s internal $.get() might suddenly use your URL, method, or headers. Prefer explicit options per call or a small wrapper around $.ajax().
Yes. Any option you pass to $.ajax(), $.get(), $.post(), or .load() overrides the matching setup key for that call only.
$.ajaxSetup() sets static defaults merged into each request. $.ajaxPrefilter() runs per request after that merge and can change options dynamically, abort, or return a dataType. Use prefilters for conditional logic; avoid setup for new global config.
Putting success, error, or complete in $.ajaxSetup() attaches them to every Ajax call, including plugins. Bind global handlers with $(document).on("ajaxSuccess"), ajaxError, and ajaxComplete instead.
Call $.ajaxSetup() again with the keys you want to change — it merges into ajaxSettings. Prefer avoiding global setup so resets are rarely needed; use a wrapper helper instead.