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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.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
What it does
options
Default key/value pairs (same as $.ajax())
Return value
Merged ajaxSettings PlainObject
Per-call options
Override matching setup keys for that request
Next $.ajaxSetup()
Merges new keys into ajaxSettings
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Pass a PlainObject of the same keys as $.ajax() (url, type, dataType, global, …).
Step 2
Later Ajax calls merge those defaults automatically.
Step 3
Override any key on a single call by passing it explicitly.
Return Value
Return Value
Description
See examples
Check the examples below for what this API returns in common cases.
jQuery Examples
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);
});
});
#users → inherits setup URL → user name
#posts → explicit url wins → post title
How It Works
Setup. Default URL points at users.
Inherit. Empty $.ajax({}) uses that URL.
Override. The second call passes its own url.
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.