Description: Set default values for future Ajax requests.
optionsA set of key/value pairs that configure the default Ajax request. All options are optional.
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()
.
For example, we could set a default for the URL parameter before pinging the server repeatedly:
$.ajaxSetup({ url: 'ping.php', });
Now each time an Ajax request is made, this URL will be used automatically:
$.ajax({ data: {'name': 'Tim'}, });
Note: Global callback functions should be set with their respective global Ajax event handler methods-
.ajaxStart()
,.ajaxStop()
,.ajaxComplete()
,.ajaxError()
,.ajaxSuccess()
,.ajaxSend()
-rather than within thesettings
object for$.ajaxSetup()
.
$.ajaxSetup({
url: "/xmlhttp/",
global: false,
type: "POST"
});
$.ajax({ data: myData });