jQuery.ajaxPrefilter( [dataTypes ], handler )Returns: undefined
Description: Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax()
.
-
version added: 1.5jQuery.ajaxPrefilter( [dataTypes ], handler )
-
dataTypesType: StringAn optional string containing one or more space-separated dataTypes
-
handlerA handler to set default values for future Ajax requests.
-
$.ajaxPrefilter()
looks like this:
1
2
3
|
|
-
options
are the request options -
originalOptions
are the options as provided to the$.ajax()
method, unmodified and, thus, without defaults fromajaxSettings
-
jqXHR
is the jqXHR object of the request
$.ajax()
would automatically abort a request to the same URL if the custom abortOnRetry
option is set to true
:
1
2
3
4
5
6
7
8
9
10
|
|
1
2
3
4
5
6
|
|
dataTypes
argument is supplied, the prefilter will be only be applied to requests with the indicated dataTypes. For example, the following only applies the given prefilter to JSON and script requests:
1
2
3
|
|
$.ajaxPrefilter()
method can also redirect a request to another dataType by returning that dataType. For example, the following sets a request as "script" if the URL has some specific properties defined in a custom isActuallyScript()
function:
1
2
3
4
5
|
|