2017-05-13 13:25:33 +02:00
|
|
|
define( [
|
2014-05-12 20:08:19 +02:00
|
|
|
"./core",
|
2017-05-13 13:25:33 +02:00
|
|
|
"./var/document",
|
2019-03-29 22:00:08 +01:00
|
|
|
"./var/isFunction",
|
2017-05-13 13:25:33 +02:00
|
|
|
"./var/rnothtmlwhite",
|
|
|
|
"./ajax/var/location",
|
2014-05-12 20:08:19 +02:00
|
|
|
"./ajax/var/nonce",
|
|
|
|
"./ajax/var/rquery",
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
"./core/init",
|
|
|
|
"./ajax/parseXML",
|
2017-05-13 13:25:33 +02:00
|
|
|
"./event/trigger",
|
|
|
|
"./deferred",
|
|
|
|
"./serialize" // jQuery.param
|
2019-03-29 22:00:08 +01:00
|
|
|
], function( jQuery, document, isFunction, rnothtmlwhite, location, nonce, rquery ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
"use strict";
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
var
|
2017-05-13 13:25:33 +02:00
|
|
|
r20 = /%20/g,
|
2014-05-12 20:08:19 +02:00
|
|
|
rhash = /#.*$/,
|
2017-05-13 13:25:33 +02:00
|
|
|
rantiCache = /([?&])_=[^&]*/,
|
2014-05-12 20:08:19 +02:00
|
|
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// #7653, #8125, #8152: local protocol detection
|
|
|
|
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
|
|
|
rnoContent = /^(?:GET|HEAD)$/,
|
|
|
|
rprotocol = /^\/\//,
|
|
|
|
|
|
|
|
/* Prefilters
|
|
|
|
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
|
|
|
|
* 2) These are called:
|
|
|
|
* - BEFORE asking for a transport
|
|
|
|
* - AFTER param serialization (s.data is a string if s.processData is true)
|
|
|
|
* 3) key is the dataType
|
|
|
|
* 4) the catchall symbol "*" can be used
|
|
|
|
* 5) execution will start with transport dataType and THEN continue down to "*" if needed
|
|
|
|
*/
|
|
|
|
prefilters = {},
|
|
|
|
|
|
|
|
/* Transports bindings
|
|
|
|
* 1) key is the dataType
|
|
|
|
* 2) the catchall symbol "*" can be used
|
|
|
|
* 3) selection will start with transport dataType and THEN go to "*" if needed
|
|
|
|
*/
|
|
|
|
transports = {},
|
|
|
|
|
|
|
|
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
2016-05-16 13:33:49 +02:00
|
|
|
allTypes = "*/".concat( "*" ),
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Anchor tag for parsing the document origin
|
|
|
|
originAnchor = document.createElement( "a" );
|
|
|
|
originAnchor.href = location.href;
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
|
|
|
function addToPrefiltersOrTransports( structure ) {
|
|
|
|
|
|
|
|
// dataTypeExpression is optional and defaults to "*"
|
|
|
|
return function( dataTypeExpression, func ) {
|
|
|
|
|
|
|
|
if ( typeof dataTypeExpression !== "string" ) {
|
|
|
|
func = dataTypeExpression;
|
|
|
|
dataTypeExpression = "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
var dataType,
|
|
|
|
i = 0,
|
2017-05-13 13:25:33 +02:00
|
|
|
dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2019-03-29 22:00:08 +01:00
|
|
|
if ( isFunction( func ) ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// For each dataType in the dataTypeExpression
|
2017-05-13 13:25:33 +02:00
|
|
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Prepend if requested
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( dataType[ 0 ] === "+" ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
dataType = dataType.slice( 1 ) || "*";
|
2017-05-13 13:25:33 +02:00
|
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Otherwise append
|
|
|
|
} else {
|
2017-05-13 13:25:33 +02:00
|
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Base inspection function for prefilters and transports
|
|
|
|
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
|
|
|
|
|
|
|
|
var inspected = {},
|
|
|
|
seekingTransport = ( structure === transports );
|
|
|
|
|
|
|
|
function inspect( dataType ) {
|
|
|
|
var selected;
|
|
|
|
inspected[ dataType ] = true;
|
|
|
|
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
|
|
|
|
var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( typeof dataTypeOrTransport === "string" &&
|
|
|
|
!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
options.dataTypes.unshift( dataTypeOrTransport );
|
|
|
|
inspect( dataTypeOrTransport );
|
|
|
|
return false;
|
|
|
|
} else if ( seekingTransport ) {
|
|
|
|
return !( selected = dataTypeOrTransport );
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
} );
|
2014-05-12 20:08:19 +02:00
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// A special extend for ajax options
|
|
|
|
// that takes "flat" options (not to be deep extended)
|
|
|
|
// Fixes #9887
|
|
|
|
function ajaxExtend( target, src ) {
|
|
|
|
var key, deep,
|
|
|
|
flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
|
|
|
|
|
|
|
for ( key in src ) {
|
|
|
|
if ( src[ key ] !== undefined ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( deep ) {
|
|
|
|
jQuery.extend( true, target, deep );
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles responses to an ajax request:
|
|
|
|
* - finds the right dataType (mediates between content-type and expected dataType)
|
|
|
|
* - returns the corresponding response
|
|
|
|
*/
|
|
|
|
function ajaxHandleResponses( s, jqXHR, responses ) {
|
|
|
|
|
|
|
|
var ct, type, finalDataType, firstDataType,
|
|
|
|
contents = s.contents,
|
|
|
|
dataTypes = s.dataTypes;
|
|
|
|
|
|
|
|
// Remove auto dataType and get content-type in the process
|
|
|
|
while ( dataTypes[ 0 ] === "*" ) {
|
|
|
|
dataTypes.shift();
|
|
|
|
if ( ct === undefined ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we're dealing with a known content-type
|
|
|
|
if ( ct ) {
|
|
|
|
for ( type in contents ) {
|
|
|
|
if ( contents[ type ] && contents[ type ].test( ct ) ) {
|
|
|
|
dataTypes.unshift( type );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if we have a response for the expected dataType
|
|
|
|
if ( dataTypes[ 0 ] in responses ) {
|
|
|
|
finalDataType = dataTypes[ 0 ];
|
|
|
|
} else {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Try convertible dataTypes
|
|
|
|
for ( type in responses ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
finalDataType = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !firstDataType ) {
|
|
|
|
firstDataType = type;
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Or just use first one
|
|
|
|
finalDataType = finalDataType || firstDataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we found a dataType
|
|
|
|
// We add the dataType to the list if needed
|
|
|
|
// and return the corresponding response
|
|
|
|
if ( finalDataType ) {
|
|
|
|
if ( finalDataType !== dataTypes[ 0 ] ) {
|
|
|
|
dataTypes.unshift( finalDataType );
|
|
|
|
}
|
|
|
|
return responses[ finalDataType ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Chain conversions given the request and the original response
|
|
|
|
* Also sets the responseXXX fields on the jqXHR instance
|
|
|
|
*/
|
|
|
|
function ajaxConvert( s, response, jqXHR, isSuccess ) {
|
|
|
|
var conv2, current, conv, tmp, prev,
|
|
|
|
converters = {},
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Work with a copy of dataTypes in case we need to modify it for conversion
|
|
|
|
dataTypes = s.dataTypes.slice();
|
|
|
|
|
|
|
|
// Create converters map with lowercased keys
|
|
|
|
if ( dataTypes[ 1 ] ) {
|
|
|
|
for ( conv in s.converters ) {
|
|
|
|
converters[ conv.toLowerCase() ] = s.converters[ conv ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current = dataTypes.shift();
|
|
|
|
|
|
|
|
// Convert to each sequential dataType
|
|
|
|
while ( current ) {
|
|
|
|
|
|
|
|
if ( s.responseFields[ current ] ) {
|
|
|
|
jqXHR[ s.responseFields[ current ] ] = response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the dataFilter if provided
|
|
|
|
if ( !prev && isSuccess && s.dataFilter ) {
|
|
|
|
response = s.dataFilter( response, s.dataType );
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = current;
|
|
|
|
current = dataTypes.shift();
|
|
|
|
|
|
|
|
if ( current ) {
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// There's only work to do if current dataType is non-auto
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( current === "*" ) {
|
|
|
|
|
|
|
|
current = prev;
|
|
|
|
|
|
|
|
// Convert response if prev dataType is non-auto and differs from current
|
|
|
|
} else if ( prev !== "*" && prev !== current ) {
|
|
|
|
|
|
|
|
// Seek a direct converter
|
|
|
|
conv = converters[ prev + " " + current ] || converters[ "* " + current ];
|
|
|
|
|
|
|
|
// If none found, seek a pair
|
|
|
|
if ( !conv ) {
|
|
|
|
for ( conv2 in converters ) {
|
|
|
|
|
|
|
|
// If conv2 outputs current
|
|
|
|
tmp = conv2.split( " " );
|
|
|
|
if ( tmp[ 1 ] === current ) {
|
|
|
|
|
|
|
|
// If prev can be converted to accepted input
|
|
|
|
conv = converters[ prev + " " + tmp[ 0 ] ] ||
|
|
|
|
converters[ "* " + tmp[ 0 ] ];
|
|
|
|
if ( conv ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Condense equivalence converters
|
|
|
|
if ( conv === true ) {
|
|
|
|
conv = converters[ conv2 ];
|
|
|
|
|
|
|
|
// Otherwise, insert the intermediate dataType
|
|
|
|
} else if ( converters[ conv2 ] !== true ) {
|
|
|
|
current = tmp[ 0 ];
|
|
|
|
dataTypes.unshift( tmp[ 1 ] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply converter (if not an equivalence)
|
|
|
|
if ( conv !== true ) {
|
|
|
|
|
|
|
|
// Unless errors are allowed to bubble, catch and return them
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( conv && s.throws ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
response = conv( response );
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
response = conv( response );
|
|
|
|
} catch ( e ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
return {
|
|
|
|
state: "parsererror",
|
|
|
|
error: conv ? e : "No conversion from " + prev + " to " + current
|
|
|
|
};
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { state: "success", data: response };
|
|
|
|
}
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
jQuery.extend( {
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Counter for holding the number of active queries
|
|
|
|
active: 0,
|
|
|
|
|
|
|
|
// Last-Modified header cache for next request
|
|
|
|
lastModified: {},
|
|
|
|
etag: {},
|
|
|
|
|
|
|
|
ajaxSettings: {
|
2017-05-13 13:25:33 +02:00
|
|
|
url: location.href,
|
2014-05-12 20:08:19 +02:00
|
|
|
type: "GET",
|
2017-05-13 13:25:33 +02:00
|
|
|
isLocal: rlocalProtocol.test( location.protocol ),
|
2014-05-12 20:08:19 +02:00
|
|
|
global: true,
|
|
|
|
processData: true,
|
|
|
|
async: true,
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
/*
|
|
|
|
timeout: 0,
|
|
|
|
data: null,
|
|
|
|
dataType: null,
|
|
|
|
username: null,
|
|
|
|
password: null,
|
|
|
|
cache: null,
|
|
|
|
throws: false,
|
|
|
|
traditional: false,
|
|
|
|
headers: {},
|
|
|
|
*/
|
|
|
|
|
|
|
|
accepts: {
|
|
|
|
"*": allTypes,
|
|
|
|
text: "text/plain",
|
|
|
|
html: "text/html",
|
|
|
|
xml: "application/xml, text/xml",
|
|
|
|
json: "application/json, text/javascript"
|
|
|
|
},
|
|
|
|
|
|
|
|
contents: {
|
2017-05-13 13:25:33 +02:00
|
|
|
xml: /\bxml\b/,
|
|
|
|
html: /\bhtml/,
|
|
|
|
json: /\bjson\b/
|
2014-05-12 20:08:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
responseFields: {
|
|
|
|
xml: "responseXML",
|
|
|
|
text: "responseText",
|
|
|
|
json: "responseJSON"
|
|
|
|
},
|
|
|
|
|
|
|
|
// Data converters
|
|
|
|
// Keys separate source (or catchall "*") and destination types with a single space
|
|
|
|
converters: {
|
|
|
|
|
|
|
|
// Convert anything to text
|
|
|
|
"* text": String,
|
|
|
|
|
|
|
|
// Text to html (true = no transformation)
|
|
|
|
"text html": true,
|
|
|
|
|
|
|
|
// Evaluate text as a json expression
|
2017-05-13 13:25:33 +02:00
|
|
|
"text json": JSON.parse,
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Parse text as xml
|
|
|
|
"text xml": jQuery.parseXML
|
|
|
|
},
|
|
|
|
|
|
|
|
// For options that shouldn't be deep extended:
|
|
|
|
// you can add your own custom options here if
|
|
|
|
// and when you create one that shouldn't be
|
|
|
|
// deep extended (see ajaxExtend)
|
|
|
|
flatOptions: {
|
|
|
|
url: true,
|
|
|
|
context: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Creates a full fledged settings object into target
|
|
|
|
// with both ajaxSettings and settings fields.
|
|
|
|
// If target is omitted, writes into ajaxSettings.
|
|
|
|
ajaxSetup: function( target, settings ) {
|
|
|
|
return settings ?
|
|
|
|
|
|
|
|
// Building a settings object
|
|
|
|
ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
|
|
|
|
|
|
|
|
// Extending ajaxSettings
|
|
|
|
ajaxExtend( jQuery.ajaxSettings, target );
|
|
|
|
},
|
|
|
|
|
|
|
|
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
|
|
|
ajaxTransport: addToPrefiltersOrTransports( transports ),
|
|
|
|
|
|
|
|
// Main method
|
|
|
|
ajax: function( url, options ) {
|
|
|
|
|
|
|
|
// If url is an object, simulate pre-1.5 signature
|
|
|
|
if ( typeof url === "object" ) {
|
|
|
|
options = url;
|
|
|
|
url = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force options to be an object
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
var transport,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// URL without anti-cache param
|
|
|
|
cacheURL,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Response headers
|
|
|
|
responseHeadersString,
|
|
|
|
responseHeaders,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// timeout handle
|
|
|
|
timeoutTimer,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
// Url cleanup var
|
|
|
|
urlAnchor,
|
|
|
|
|
|
|
|
// Request state (becomes false upon send and true upon completion)
|
|
|
|
completed,
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// To know if global events are to be dispatched
|
|
|
|
fireGlobals,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Loop variable
|
|
|
|
i,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
// uncached part of the url
|
|
|
|
uncached,
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Create the final options object
|
|
|
|
s = jQuery.ajaxSetup( {}, options ),
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Callbacks context
|
|
|
|
callbackContext = s.context || s,
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
2017-05-13 13:25:33 +02:00
|
|
|
globalEventContext = s.context &&
|
|
|
|
( callbackContext.nodeType || callbackContext.jquery ) ?
|
|
|
|
jQuery( callbackContext ) :
|
|
|
|
jQuery.event,
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Deferreds
|
|
|
|
deferred = jQuery.Deferred(),
|
2017-05-13 13:25:33 +02:00
|
|
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode = s.statusCode || {},
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Headers (they are sent all at once)
|
|
|
|
requestHeaders = {},
|
|
|
|
requestHeadersNames = {},
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Default abort message
|
|
|
|
strAbort = "canceled",
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Fake xhr
|
|
|
|
jqXHR = {
|
|
|
|
readyState: 0,
|
|
|
|
|
|
|
|
// Builds headers hashtable if needed
|
|
|
|
getResponseHeader: function( key ) {
|
|
|
|
var match;
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( completed ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( !responseHeaders ) {
|
|
|
|
responseHeaders = {};
|
2017-05-13 13:25:33 +02:00
|
|
|
while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
|
|
|
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match = responseHeaders[ key.toLowerCase() ];
|
|
|
|
}
|
|
|
|
return match == null ? null : match;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Raw string
|
|
|
|
getAllResponseHeaders: function() {
|
2017-05-13 13:25:33 +02:00
|
|
|
return completed ? responseHeadersString : null;
|
2014-05-12 20:08:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Caches the header
|
|
|
|
setRequestHeader: function( name, value ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( completed == null ) {
|
|
|
|
name = requestHeadersNames[ name.toLowerCase() ] =
|
|
|
|
requestHeadersNames[ name.toLowerCase() ] || name;
|
2014-05-12 20:08:19 +02:00
|
|
|
requestHeaders[ name ] = value;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Overrides response content-type header
|
|
|
|
overrideMimeType: function( type ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( completed == null ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
s.mimeType = type;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode: function( map ) {
|
|
|
|
var code;
|
|
|
|
if ( map ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( completed ) {
|
|
|
|
|
|
|
|
// Execute the appropriate callbacks
|
|
|
|
jqXHR.always( map[ jqXHR.status ] );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Lazy-add the new callbacks in a way that preserves old ones
|
2014-05-12 20:08:19 +02:00
|
|
|
for ( code in map ) {
|
|
|
|
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Cancel the request
|
|
|
|
abort: function( statusText ) {
|
|
|
|
var finalText = statusText || strAbort;
|
|
|
|
if ( transport ) {
|
|
|
|
transport.abort( finalText );
|
|
|
|
}
|
|
|
|
done( 0, finalText );
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Attach deferreds
|
2017-05-13 13:25:33 +02:00
|
|
|
deferred.promise( jqXHR );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Add protocol if not provided (prefilters might expect it)
|
|
|
|
// Handle falsy url in the settings object (#10093: consistency with old signature)
|
|
|
|
// We also use the url parameter if available
|
2017-05-13 13:25:33 +02:00
|
|
|
s.url = ( ( url || s.url || location.href ) + "" )
|
|
|
|
.replace( rprotocol, location.protocol + "//" );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Alias method option to type as per ticket #12004
|
|
|
|
s.type = options.method || options.type || s.method || s.type;
|
|
|
|
|
|
|
|
// Extract dataTypes list
|
2017-05-13 13:25:33 +02:00
|
|
|
s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ];
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// A cross-domain request is in order when the origin doesn't match the current origin.
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( s.crossDomain == null ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
urlAnchor = document.createElement( "a" );
|
|
|
|
|
2019-03-29 22:00:08 +01:00
|
|
|
// Support: IE <=8 - 11, Edge 12 - 15
|
2017-05-13 13:25:33 +02:00
|
|
|
// IE throws exception on accessing the href property if url is malformed,
|
|
|
|
// e.g. http://example.com:80x/
|
|
|
|
try {
|
|
|
|
urlAnchor.href = s.url;
|
|
|
|
|
|
|
|
// Support: IE <=8 - 11 only
|
|
|
|
// Anchor's host property isn't correctly set when s.url is relative
|
|
|
|
urlAnchor.href = urlAnchor.href;
|
|
|
|
s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
|
|
|
|
urlAnchor.protocol + "//" + urlAnchor.host;
|
|
|
|
} catch ( e ) {
|
|
|
|
|
|
|
|
// If there is an error parsing the URL, assume it is crossDomain,
|
|
|
|
// it can be rejected by the transport if it is invalid
|
|
|
|
s.crossDomain = true;
|
|
|
|
}
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert data if not already a string
|
|
|
|
if ( s.data && s.processData && typeof s.data !== "string" ) {
|
|
|
|
s.data = jQuery.param( s.data, s.traditional );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply prefilters
|
|
|
|
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
|
|
|
|
|
|
|
// If request was aborted inside a prefilter, stop there
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( completed ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
return jqXHR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can fire global events as of now if asked to
|
2016-05-16 13:33:49 +02:00
|
|
|
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
|
|
|
|
fireGlobals = jQuery.event && s.global;
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Watch for a new set of requests
|
|
|
|
if ( fireGlobals && jQuery.active++ === 0 ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
jQuery.event.trigger( "ajaxStart" );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Uppercase the type
|
|
|
|
s.type = s.type.toUpperCase();
|
|
|
|
|
|
|
|
// Determine if request has content
|
|
|
|
s.hasContent = !rnoContent.test( s.type );
|
|
|
|
|
|
|
|
// Save the URL in case we're toying with the If-Modified-Since
|
|
|
|
// and/or If-None-Match header later on
|
2017-05-13 13:25:33 +02:00
|
|
|
// Remove hash to simplify url manipulation
|
|
|
|
cacheURL = s.url.replace( rhash, "" );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// More options handling for requests with no content
|
|
|
|
if ( !s.hasContent ) {
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Remember the hash so we can put it back
|
|
|
|
uncached = s.url.slice( cacheURL.length );
|
|
|
|
|
2019-03-29 22:00:08 +01:00
|
|
|
// If data is available and should be processed, append data to url
|
|
|
|
if ( s.data && ( s.processData || typeof s.data === "string" ) ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// #9682: remove data so that it's not used in an eventual retry
|
|
|
|
delete s.data;
|
|
|
|
}
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Add or update anti-cache param if needed
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( s.cache === false ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
cacheURL = cacheURL.replace( rantiCache, "$1" );
|
|
|
|
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
|
|
|
|
}
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Put hash and anti-cache on the URL that will be requested (gh-1732)
|
|
|
|
s.url = cacheURL + uncached;
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Change '%20' to '+' if this is encoded form body content (gh-2658)
|
|
|
|
} else if ( s.data && s.processData &&
|
|
|
|
( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {
|
|
|
|
s.data = s.data.replace( r20, "+" );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
|
|
if ( s.ifModified ) {
|
|
|
|
if ( jQuery.lastModified[ cacheURL ] ) {
|
|
|
|
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
|
|
|
}
|
|
|
|
if ( jQuery.etag[ cacheURL ] ) {
|
|
|
|
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the correct header, if data is being sent
|
|
|
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
|
|
|
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the Accepts header for the server, depending on the dataType
|
|
|
|
jqXHR.setRequestHeader(
|
|
|
|
"Accept",
|
2017-05-13 13:25:33 +02:00
|
|
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
|
|
|
s.accepts[ s.dataTypes[ 0 ] ] +
|
|
|
|
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
2014-05-12 20:08:19 +02:00
|
|
|
s.accepts[ "*" ]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check for headers option
|
|
|
|
for ( i in s.headers ) {
|
|
|
|
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow custom headers/mimetypes and early abort
|
2017-05-13 13:25:33 +02:00
|
|
|
if ( s.beforeSend &&
|
|
|
|
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Abort if not done already and return
|
|
|
|
return jqXHR.abort();
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:33:49 +02:00
|
|
|
// Aborting is no longer a cancellation
|
2014-05-12 20:08:19 +02:00
|
|
|
strAbort = "abort";
|
|
|
|
|
|
|
|
// Install callbacks on deferreds
|
2017-05-13 13:25:33 +02:00
|
|
|
completeDeferred.add( s.complete );
|
|
|
|
jqXHR.done( s.success );
|
|
|
|
jqXHR.fail( s.error );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Get transport
|
|
|
|
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
|
|
|
|
|
|
|
// If no transport, we auto-abort
|
|
|
|
if ( !transport ) {
|
|
|
|
done( -1, "No Transport" );
|
|
|
|
} else {
|
|
|
|
jqXHR.readyState = 1;
|
|
|
|
|
|
|
|
// Send global event
|
|
|
|
if ( fireGlobals ) {
|
|
|
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
// If request was aborted inside ajaxSend, stop there
|
|
|
|
if ( completed ) {
|
|
|
|
return jqXHR;
|
|
|
|
}
|
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Timeout
|
|
|
|
if ( s.async && s.timeout > 0 ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
timeoutTimer = window.setTimeout( function() {
|
|
|
|
jqXHR.abort( "timeout" );
|
2014-05-12 20:08:19 +02:00
|
|
|
}, s.timeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-05-13 13:25:33 +02:00
|
|
|
completed = false;
|
2014-05-12 20:08:19 +02:00
|
|
|
transport.send( requestHeaders, done );
|
|
|
|
} catch ( e ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
// Rethrow post-completion exceptions
|
|
|
|
if ( completed ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
throw e;
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
|
|
|
|
// Propagate others as results
|
|
|
|
done( -1, e );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Callback for when everything is done
|
|
|
|
function done( status, nativeStatusText, responses, headers ) {
|
|
|
|
var isSuccess, success, error, response, modified,
|
|
|
|
statusText = nativeStatusText;
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// Ignore repeat invocations
|
|
|
|
if ( completed ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
completed = true;
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
// Clear timeout if it exists
|
|
|
|
if ( timeoutTimer ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
window.clearTimeout( timeoutTimer );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dereference transport for early garbage collection
|
|
|
|
// (no matter how long the jqXHR object will be used)
|
|
|
|
transport = undefined;
|
|
|
|
|
|
|
|
// Cache response headers
|
|
|
|
responseHeadersString = headers || "";
|
|
|
|
|
|
|
|
// Set readyState
|
|
|
|
jqXHR.readyState = status > 0 ? 4 : 0;
|
|
|
|
|
|
|
|
// Determine if successful
|
|
|
|
isSuccess = status >= 200 && status < 300 || status === 304;
|
|
|
|
|
|
|
|
// Get response data
|
|
|
|
if ( responses ) {
|
|
|
|
response = ajaxHandleResponses( s, jqXHR, responses );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert no matter what (that way responseXXX fields are always set)
|
|
|
|
response = ajaxConvert( s, response, jqXHR, isSuccess );
|
|
|
|
|
|
|
|
// If successful, handle type chaining
|
|
|
|
if ( isSuccess ) {
|
|
|
|
|
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
|
|
if ( s.ifModified ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
modified = jqXHR.getResponseHeader( "Last-Modified" );
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( modified ) {
|
|
|
|
jQuery.lastModified[ cacheURL ] = modified;
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
modified = jqXHR.getResponseHeader( "etag" );
|
2014-05-12 20:08:19 +02:00
|
|
|
if ( modified ) {
|
|
|
|
jQuery.etag[ cacheURL ] = modified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no content
|
|
|
|
if ( status === 204 || s.type === "HEAD" ) {
|
|
|
|
statusText = "nocontent";
|
|
|
|
|
|
|
|
// if not modified
|
|
|
|
} else if ( status === 304 ) {
|
|
|
|
statusText = "notmodified";
|
|
|
|
|
|
|
|
// If we have data, let's convert it
|
|
|
|
} else {
|
|
|
|
statusText = response.state;
|
|
|
|
success = response.data;
|
|
|
|
error = response.error;
|
|
|
|
isSuccess = !error;
|
|
|
|
}
|
|
|
|
} else {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2016-05-16 13:33:49 +02:00
|
|
|
// Extract error from statusText and normalize for non-aborts
|
2014-05-12 20:08:19 +02:00
|
|
|
error = statusText;
|
|
|
|
if ( status || !statusText ) {
|
|
|
|
statusText = "error";
|
|
|
|
if ( status < 0 ) {
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set data for the fake xhr object
|
|
|
|
jqXHR.status = status;
|
|
|
|
jqXHR.statusText = ( nativeStatusText || statusText ) + "";
|
|
|
|
|
|
|
|
// Success/Error
|
|
|
|
if ( isSuccess ) {
|
|
|
|
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
|
|
|
} else {
|
|
|
|
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status-dependent callbacks
|
|
|
|
jqXHR.statusCode( statusCode );
|
|
|
|
statusCode = undefined;
|
|
|
|
|
|
|
|
if ( fireGlobals ) {
|
|
|
|
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
|
|
|
|
[ jqXHR, s, isSuccess ? success : error ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Complete
|
|
|
|
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
|
|
|
|
|
|
|
|
if ( fireGlobals ) {
|
|
|
|
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2014-05-12 20:08:19 +02:00
|
|
|
// Handle the global AJAX counter
|
|
|
|
if ( !( --jQuery.active ) ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jqXHR;
|
|
|
|
},
|
|
|
|
|
|
|
|
getJSON: function( url, data, callback ) {
|
|
|
|
return jQuery.get( url, data, callback, "json" );
|
|
|
|
},
|
|
|
|
|
|
|
|
getScript: function( url, callback ) {
|
|
|
|
return jQuery.get( url, undefined, callback, "script" );
|
|
|
|
}
|
2017-05-13 13:25:33 +02:00
|
|
|
} );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
jQuery.each( [ "get", "post" ], function( i, method ) {
|
|
|
|
jQuery[ method ] = function( url, data, callback, type ) {
|
2017-05-13 13:25:33 +02:00
|
|
|
|
2016-05-16 13:33:49 +02:00
|
|
|
// Shift arguments if data argument was omitted
|
2019-03-29 22:00:08 +01:00
|
|
|
if ( isFunction( data ) ) {
|
2014-05-12 20:08:19 +02:00
|
|
|
type = type || callback;
|
|
|
|
callback = data;
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
// The url can be an options object (which then must have .url)
|
|
|
|
return jQuery.ajax( jQuery.extend( {
|
2014-05-12 20:08:19 +02:00
|
|
|
url: url,
|
|
|
|
type: method,
|
|
|
|
dataType: type,
|
|
|
|
data: data,
|
|
|
|
success: callback
|
2017-05-13 13:25:33 +02:00
|
|
|
}, jQuery.isPlainObject( url ) && url ) );
|
2014-05-12 20:08:19 +02:00
|
|
|
};
|
2017-05-13 13:25:33 +02:00
|
|
|
} );
|
2014-05-12 20:08:19 +02:00
|
|
|
|
|
|
|
return jQuery;
|
2017-05-13 13:25:33 +02:00
|
|
|
} );
|