jQuery.ajaxSetup( options ) Returns:
Description: Set default values for future Ajax requests.
-
version added: 1.1jQuery.ajaxSetup( options )
-
optionsType: PlainObjectA 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, the following sets a default for the url
parameter before pinging the server repeatedly:
1
2
3
|
|
Now each time an Ajax request is made, the "ping.php" URL will be used automatically:
1
2
3
4
|
|
Note: Global callback functions should be set with their respective global Ajax event handler methods—
.ajaxStart()
,.ajaxStop()
,.ajaxComplete()
,.ajaxError()
,.ajaxSuccess()
,.ajaxSend()
—rather than within theoptions
object for$.ajaxSetup()
.
Example:
Sets the defaults for Ajax requests to the url "/xmlhttp/", disables global handlers and uses POST instead of GET. The following Ajax requests then sends some data without having to set anything else.
1
2
3
4
5
6
7
|
|