A repository of over 1000 quality jQuery plugins

jQuery jQuery.ajaxSetup()

Learn all about the jQuery function jQuery.ajaxSetup().

For details on the settings available for $.ajaxSetup(), see $.ajax().

All subsequent Ajax calls using any function will use the new settings, unless overridden by the individual calls, until the next invocation of $.ajaxSetup().

Note: The settings specified here will affect all calls to $.ajax or Ajax-based derivatives such as $.get(). This can cause undesirable behavior since other callers (for example, plugins) may be expecting the normal default settings. For that reason we strongly recommend against using this API. Instead, set the options explicitly in the call or define a simple plugin to do so.

For example, the following sets a default for the url parameter before pinging the server repeatedly:

1
2
3
$.ajaxSetup({
url: "ping.php"
});

Now each time an Ajax request is made, the "ping.php" URL will be used automatically:

1
2
3
4
$.ajax({
// url not set here; uses ping.php
data: { "name": "Dan" }
});

Note: Global callback functions should be set with their respective global Ajax event handler methods—.ajaxStart(), .ajaxStop(), .ajaxComplete(), .ajaxError(), .ajaxSuccess(), .ajaxSend()—rather than within the options object for $.ajaxSetup().