2015-09-02 23:52:01 +00:00
|
|
|
define( [
|
2013-08-15 18:15:49 +00:00
|
|
|
"./core",
|
2015-07-28 10:58:44 +00:00
|
|
|
"./var/document",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./var/rnotwhite",
|
2015-07-28 10:58:44 +00:00
|
|
|
"./ajax/var/location",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./ajax/var/nonce",
|
|
|
|
"./ajax/var/rquery",
|
2013-09-10 00:13:01 +00:00
|
|
|
"./core/init",
|
2013-09-09 01:05:07 +00:00
|
|
|
"./ajax/parseJSON",
|
|
|
|
"./ajax/parseXML",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./deferred"
|
2015-07-28 10:58:44 +00:00
|
|
|
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2012-09-18 21:39:44 +00:00
|
|
|
var
|
2010-12-25 17:54:37 +00:00
|
|
|
rhash = /#.*$/,
|
2012-11-23 15:29:08 +00:00
|
|
|
rts = /([?&])_=[^&]*/,
|
2014-11-23 01:29:13 +00:00
|
|
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-02-03 04:19:15 +00:00
|
|
|
// #7653, #8125, #8152: local protocol detection
|
2012-11-23 15:29:08 +00:00
|
|
|
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
2012-08-24 15:59:01 +00:00
|
|
|
rnoContent = /^(?:GET|HEAD)$/,
|
2011-01-26 00:36:05 +00:00
|
|
|
rprotocol = /^\/\//,
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
/* Prefilters
|
2012-01-20 02:47:23 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2011-01-22 03:45:20 +00:00
|
|
|
prefilters = {},
|
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
/* Transports bindings
|
2012-01-20 02:47:23 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2011-02-02 19:52:26 +00:00
|
|
|
transports = {},
|
|
|
|
|
2011-08-23 02:32:06 +00:00
|
|
|
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
2014-11-03 18:53:22 +00:00
|
|
|
allTypes = "*/".concat( "*" ),
|
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
// Anchor tag for parsing the document origin
|
|
|
|
originAnchor = document.createElement( "a" );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
originAnchor.href = location.href;
|
2011-02-03 01:53:10 +00:00
|
|
|
|
2011-01-23 21:03:24 +00: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 = "*";
|
|
|
|
}
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
var dataType,
|
2012-07-10 01:38:11 +00:00
|
|
|
i = 0,
|
2013-08-15 18:15:49 +00:00
|
|
|
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
|
2011-01-23 21:03:24 +00:00
|
|
|
|
2012-07-10 01:38:11 +00:00
|
|
|
if ( jQuery.isFunction( func ) ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-01-23 21:03:24 +00:00
|
|
|
// For each dataType in the dataTypeExpression
|
2015-09-02 23:52:01 +00:00
|
|
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Prepend if requested
|
2014-11-03 18:53:22 +00:00
|
|
|
if ( dataType[ 0 ] === "+" ) {
|
2012-11-23 15:29:08 +00:00
|
|
|
dataType = dataType.slice( 1 ) || "*";
|
2015-09-02 23:52:01 +00:00
|
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
2012-11-23 15:29:08 +00:00
|
|
|
|
|
|
|
// Otherwise append
|
|
|
|
} else {
|
2015-09-02 23:52:01 +00:00
|
|
|
( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-04-19 07:29:20 +00:00
|
|
|
// Base inspection function for prefilters and transports
|
2012-10-16 13:40:42 +00:00
|
|
|
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 );
|
2014-07-17 17:25:59 +00:00
|
|
|
if ( typeof dataTypeOrTransport === "string" &&
|
|
|
|
!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
|
|
|
|
2012-10-16 13:40:42 +00:00
|
|
|
options.dataTypes.unshift( dataTypeOrTransport );
|
|
|
|
inspect( dataTypeOrTransport );
|
|
|
|
return false;
|
|
|
|
} else if ( seekingTransport ) {
|
|
|
|
return !( selected = dataTypeOrTransport );
|
2011-01-24 03:22:46 +00:00
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-10-16 13:40:42 +00:00
|
|
|
return selected;
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
2012-10-16 13:40:42 +00:00
|
|
|
|
|
|
|
return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 00:10:17 +00:00
|
|
|
// A special extend for ajax options
|
|
|
|
// that takes "flat" options (not to be deep extended)
|
|
|
|
// Fixes #9887
|
|
|
|
function ajaxExtend( target, src ) {
|
2013-01-29 00:04:58 +00:00
|
|
|
var deep, key,
|
2011-07-23 00:10:17 +00:00
|
|
|
flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
2012-11-23 15:29:08 +00:00
|
|
|
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( key in src ) {
|
2011-07-23 00:10:17 +00:00
|
|
|
if ( src[ key ] !== undefined ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
2011-07-23 00:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( deep ) {
|
|
|
|
jQuery.extend( true, target, deep );
|
|
|
|
}
|
2012-11-23 15:29:08 +00:00
|
|
|
|
|
|
|
return target;
|
2011-07-23 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 03:54:07 +00:00
|
|
|
/* 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 firstDataType, ct, finalDataType, type,
|
|
|
|
contents = s.contents,
|
|
|
|
dataTypes = s.dataTypes;
|
|
|
|
|
|
|
|
// Remove auto dataType and get content-type in the process
|
2013-11-07 20:14:23 +00:00
|
|
|
while ( dataTypes[ 0 ] === "*" ) {
|
2013-09-10 03:54:07 +00:00
|
|
|
dataTypes.shift();
|
|
|
|
if ( ct === undefined ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
2013-09-10 03:54:07 +00: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 {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-09-10 03:54:07 +00:00
|
|
|
// Try convertible dataTypes
|
|
|
|
for ( type in responses ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
2013-09-10 03:54:07 +00:00
|
|
|
finalDataType = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !firstDataType ) {
|
|
|
|
firstDataType = type;
|
|
|
|
}
|
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-09-10 03:54:07 +00: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 = {},
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-09-10 03:54:07 +00: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 ) {
|
|
|
|
|
|
|
|
// There's only work to do if current dataType is non-auto
|
|
|
|
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 ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-09-10 03:54:07 +00: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
|
2015-09-03 00:03:12 +00:00
|
|
|
if ( conv && s.throws ) {
|
2013-09-10 03:54:07 +00:00
|
|
|
response = conv( response );
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
response = conv( response );
|
|
|
|
} catch ( e ) {
|
2014-07-17 17:25:59 +00:00
|
|
|
return {
|
|
|
|
state: "parsererror",
|
|
|
|
error: conv ? e : "No conversion from " + prev + " to " + current
|
|
|
|
};
|
2013-09-10 03:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { state: "success", data: response };
|
|
|
|
}
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery.extend( {
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Counter for holding the number of active queries
|
|
|
|
active: 0,
|
2012-10-16 15:37:15 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Last-Modified header cache for next request
|
|
|
|
lastModified: {},
|
|
|
|
etag: {},
|
2006-08-17 04:18:32 +00:00
|
|
|
|
2006-12-22 13:56:36 +00:00
|
|
|
ajaxSettings: {
|
2014-11-23 01:29:13 +00:00
|
|
|
url: location.href,
|
2012-11-23 15:29:08 +00:00
|
|
|
type: "GET",
|
2014-11-23 01:29:13 +00:00
|
|
|
isLocal: rlocalProtocol.test( location.protocol ),
|
2006-12-22 13:56:36 +00:00
|
|
|
global: true,
|
|
|
|
processData: true,
|
2007-01-14 22:51:55 +00:00
|
|
|
async: true,
|
2012-11-23 15:29:08 +00:00
|
|
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
2009-01-04 21:15:02 +00:00
|
|
|
/*
|
|
|
|
timeout: 0,
|
2008-01-07 01:03:31 +00:00
|
|
|
data: null,
|
2010-12-09 18:34:28 +00:00
|
|
|
dataType: null,
|
2008-01-07 01:03:31 +00:00
|
|
|
username: null,
|
2008-01-14 18:19:28 +00:00
|
|
|
password: null,
|
2010-12-09 18:34:28 +00:00
|
|
|
cache: null,
|
2012-05-31 15:31:13 +00:00
|
|
|
throws: false,
|
2009-12-22 13:09:56 +00:00
|
|
|
traditional: false,
|
2011-01-16 02:05:03 +00:00
|
|
|
headers: {},
|
2009-01-04 21:15:02 +00:00
|
|
|
*/
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2008-01-14 18:19:28 +00:00
|
|
|
accepts: {
|
2012-11-23 15:29:08 +00:00
|
|
|
"*": allTypes,
|
2008-01-14 18:19:28 +00:00
|
|
|
text: "text/plain",
|
2012-11-23 15:29:08 +00:00
|
|
|
html: "text/html",
|
|
|
|
xml: "application/xml, text/xml",
|
|
|
|
json: "application/json, text/javascript"
|
2010-12-09 18:34:28 +00:00
|
|
|
},
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-28 01:30:51 +00:00
|
|
|
contents: {
|
2010-12-09 18:34:28 +00:00
|
|
|
xml: /xml/,
|
|
|
|
html: /html/,
|
|
|
|
json: /json/
|
|
|
|
},
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-01-20 18:40:51 +00:00
|
|
|
responseFields: {
|
|
|
|
xml: "responseXML",
|
2013-02-08 15:26:36 +00:00
|
|
|
text: "responseText",
|
|
|
|
json: "responseJSON"
|
2011-01-20 18:40:51 +00:00
|
|
|
},
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Data converters
|
|
|
|
// Keys separate source (or catchall "*") and destination types with a single space
|
2010-12-28 01:30:51 +00:00
|
|
|
converters: {
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Convert anything to text
|
2013-02-20 23:01:06 +00:00
|
|
|
"* text": String,
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-25 14:38:33 +00:00
|
|
|
// Text to html (true = no transformation)
|
|
|
|
"text html": true,
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Evaluate text as a json expression
|
2010-12-24 17:02:45 +00:00
|
|
|
"text json": jQuery.parseJSON,
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Parse text as xml
|
2010-12-24 17:02:45 +00:00
|
|
|
"text xml": jQuery.parseXML
|
2011-07-23 00:10:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// 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: {
|
2012-11-23 15:29:08 +00:00
|
|
|
url: true,
|
|
|
|
context: true
|
2006-12-21 13:35:32 +00:00
|
|
|
}
|
2010-12-09 18:34:28 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// 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 );
|
|
|
|
},
|
|
|
|
|
2011-01-23 21:03:24 +00:00
|
|
|
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
|
|
|
ajaxTransport: addToPrefiltersOrTransports( transports ),
|
2011-01-20 03:12:15 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Main method
|
2011-01-23 04:51:41 +00:00
|
|
|
ajax: function( url, options ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-01 03:37:28 +00:00
|
|
|
// If url is an object, simulate pre-1.5 signature
|
|
|
|
if ( typeof url === "object" ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
options = url;
|
2011-01-20 15:22:36 +00:00
|
|
|
url = undefined;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Force options to be an object
|
|
|
|
options = options || {};
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
var
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-01-29 00:04:58 +00:00
|
|
|
// Loop variable
|
|
|
|
i,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-29 16:16:42 +00:00
|
|
|
// URL without anti-cache param
|
|
|
|
cacheURL,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-01-29 00:04:58 +00:00
|
|
|
// Response headers as string
|
2012-07-10 01:38:11 +00:00
|
|
|
responseHeadersString,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-07-10 01:38:11 +00:00
|
|
|
// timeout handle
|
|
|
|
timeoutTimer,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
// Url cleanup var
|
|
|
|
urlAnchor,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-07-10 01:38:11 +00:00
|
|
|
// To know if global events are to be dispatched
|
|
|
|
fireGlobals,
|
2013-01-29 00:04:58 +00:00
|
|
|
|
|
|
|
transport,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2013-01-29 00:04:58 +00:00
|
|
|
// Response headers
|
|
|
|
responseHeaders,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-07-10 01:38:11 +00:00
|
|
|
// Create the final options object
|
2011-02-12 02:59:46 +00:00
|
|
|
s = jQuery.ajaxSetup( {}, options ),
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-01-31 16:23:36 +00:00
|
|
|
// Callbacks context
|
2011-02-12 02:59:46 +00:00
|
|
|
callbackContext = s.context || s,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
2014-07-17 17:25:59 +00:00
|
|
|
globalEventContext = s.context &&
|
|
|
|
( callbackContext.nodeType || callbackContext.jquery ) ?
|
|
|
|
jQuery( callbackContext ) :
|
|
|
|
jQuery.event,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Deferreds
|
|
|
|
deferred = jQuery.Deferred(),
|
2015-09-02 23:52:01 +00:00
|
|
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
|
|
|
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode = s.statusCode || {},
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Headers (they are sent all at once)
|
|
|
|
requestHeaders = {},
|
2011-04-19 07:29:20 +00:00
|
|
|
requestHeadersNames = {},
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-02-01 15:00:30 +00:00
|
|
|
// The jqXHR state
|
2010-12-25 17:54:37 +00:00
|
|
|
state = 0,
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-04-02 00:04:46 +00:00
|
|
|
// Default abort message
|
|
|
|
strAbort = "canceled",
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Fake xhr
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR = {
|
2010-12-25 17:54:37 +00:00
|
|
|
readyState: 0,
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Builds headers hashtable if needed
|
2011-01-19 16:21:51 +00:00
|
|
|
getResponseHeader: function( key ) {
|
|
|
|
var match;
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( state === 2 ) {
|
2011-01-19 16:21:51 +00:00
|
|
|
if ( !responseHeaders ) {
|
2011-01-16 01:57:39 +00:00
|
|
|
responseHeaders = {};
|
2015-09-02 23:52:01 +00:00
|
|
|
while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
|
|
|
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
match = responseHeaders[ key.toLowerCase() ];
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2012-11-23 15:29:08 +00:00
|
|
|
return match == null ? null : match;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Raw string
|
|
|
|
getAllResponseHeaders: function() {
|
|
|
|
return state === 2 ? responseHeadersString : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Caches the header
|
|
|
|
setRequestHeader: function( name, value ) {
|
|
|
|
var lname = name.toLowerCase();
|
|
|
|
if ( !state ) {
|
|
|
|
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
|
|
|
|
requestHeaders[ name ] = value;
|
|
|
|
}
|
|
|
|
return this;
|
2010-12-25 17:54:37 +00:00
|
|
|
},
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-09 16:47:33 +00:00
|
|
|
// Overrides response content-type header
|
|
|
|
overrideMimeType: function( type ) {
|
2011-02-11 06:07:06 +00:00
|
|
|
if ( !state ) {
|
2011-02-09 16:47:33 +00:00
|
|
|
s.mimeType = type;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode: function( map ) {
|
|
|
|
var code;
|
|
|
|
if ( map ) {
|
|
|
|
if ( state < 2 ) {
|
|
|
|
for ( code in map ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Lazy-add the new callback in a way that preserves old ones
|
|
|
|
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Execute the appropriate callbacks
|
|
|
|
jqXHR.always( map[ jqXHR.status ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Cancel the request
|
|
|
|
abort: function( statusText ) {
|
2012-11-23 15:29:08 +00:00
|
|
|
var finalText = statusText || strAbort;
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( transport ) {
|
2012-11-23 15:29:08 +00:00
|
|
|
transport.abort( finalText );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2012-11-23 15:29:08 +00:00
|
|
|
done( 0, finalText );
|
2010-12-25 17:54:37 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-28 03:13:44 +00:00
|
|
|
// Attach deferreds
|
2015-02-15 02:41:38 +00:00
|
|
|
deferred.promise( jqXHR );
|
2011-01-13 16:01:25 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Remove hash character (#7531: and string promotion)
|
2014-11-03 18:53:22 +00:00
|
|
|
// Add protocol if not provided (prefilters might expect it)
|
2012-10-16 15:37:15 +00:00
|
|
|
// Handle falsy url in the settings object (#10093: consistency with old signature)
|
2011-01-20 15:22:36 +00:00
|
|
|
// We also use the url parameter if available
|
2014-11-23 01:29:13 +00:00
|
|
|
s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
|
|
|
|
.replace( rprotocol, location.protocol + "//" );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2012-11-28 22:59:37 +00:00
|
|
|
// Alias method option to type as per ticket #12004
|
|
|
|
s.type = options.method || options.type || s.method || s.type;
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Extract dataTypes list
|
2013-11-07 20:14:23 +00:00
|
|
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
// A cross-domain request is in order when the origin doesn't match the current origin
|
2011-03-10 23:17:38 +00:00
|
|
|
if ( s.crossDomain == null ) {
|
2014-11-23 01:29:13 +00:00
|
|
|
urlAnchor = document.createElement( "a" );
|
|
|
|
|
|
|
|
// Support: IE8-11+
|
|
|
|
// IE throws exception if url is malformed, e.g. http://example.com:80x/
|
|
|
|
try {
|
|
|
|
urlAnchor.href = s.url;
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
// Support: IE8-11+
|
|
|
|
// 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 ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2014-11-23 01:29:13 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2011-01-09 15:50:13 +00:00
|
|
|
}
|
2010-12-25 17:54:37 +00:00
|
|
|
|
|
|
|
// Convert data if not already a string
|
2011-01-16 04:24:14 +00:00
|
|
|
if ( s.data && s.processData && typeof s.data !== "string" ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
s.data = jQuery.param( s.data, s.traditional );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Apply prefilters
|
2011-02-01 15:00:30 +00:00
|
|
|
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
2011-01-09 15:32:51 +00:00
|
|
|
|
2012-01-22 19:53:50 +00:00
|
|
|
// If request was aborted inside a prefilter, stop there
|
2011-02-04 21:19:23 +00:00
|
|
|
if ( state === 2 ) {
|
2012-04-01 23:54:19 +00:00
|
|
|
return jqXHR;
|
2011-02-04 21:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We can fire global events as of now if asked to
|
2014-05-30 13:48:43 +00:00
|
|
|
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
|
|
|
|
fireGlobals = jQuery.event && s.global;
|
2011-02-04 21:19:23 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Watch for a new set of requests
|
|
|
|
if ( fireGlobals && jQuery.active++ === 0 ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery.event.trigger( "ajaxStart" );
|
2012-11-23 15:29:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 04:24:14 +00:00
|
|
|
// Uppercase the type
|
|
|
|
s.type = s.type.toUpperCase();
|
|
|
|
|
|
|
|
// Determine if request has content
|
2011-01-23 04:51:41 +00:00
|
|
|
s.hasContent = !rnoContent.test( s.type );
|
2011-01-16 04:24:14 +00:00
|
|
|
|
2012-11-29 16:16:42 +00:00
|
|
|
// Save the URL in case we're toying with the If-Modified-Since
|
|
|
|
// and/or If-None-Match header later on
|
|
|
|
cacheURL = s.url;
|
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// More options handling for requests with no content
|
2011-01-23 04:51:41 +00:00
|
|
|
if ( !s.hasContent ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// If data is available, append data to url
|
|
|
|
if ( s.data ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-07-01 00:11:26 +00:00
|
|
|
// #9682: remove data so that it's not used in an eventual retry
|
|
|
|
delete s.data;
|
2011-01-16 01:57:39 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Add anti-cache in url if needed
|
|
|
|
if ( s.cache === false ) {
|
2012-11-29 16:16:42 +00:00
|
|
|
s.url = rts.test( cacheURL ) ?
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// If there is already a '_' parameter, set its value
|
2013-08-15 18:15:49 +00:00
|
|
|
cacheURL.replace( rts, "$1_=" + nonce++ ) :
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Otherwise add one to the end
|
2013-08-15 18:15:49 +00:00
|
|
|
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
|
2011-01-16 01:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
|
|
if ( s.ifModified ) {
|
2012-11-29 16:16:42 +00:00
|
|
|
if ( jQuery.lastModified[ cacheURL ] ) {
|
|
|
|
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2012-11-29 16:16:42 +00:00
|
|
|
if ( jQuery.etag[ cacheURL ] ) {
|
|
|
|
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Set the Accepts header for the server, depending on the dataType
|
2011-04-15 21:16:43 +00:00
|
|
|
jqXHR.setRequestHeader(
|
|
|
|
"Accept",
|
2015-09-02 23:52:01 +00:00
|
|
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
|
|
|
s.accepts[ s.dataTypes[ 0 ] ] +
|
2014-07-17 17:25:59 +00:00
|
|
|
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
2011-04-15 21:16:43 +00:00
|
|
|
s.accepts[ "*" ]
|
|
|
|
);
|
2011-01-16 01:57:39 +00:00
|
|
|
|
|
|
|
// Check for headers option
|
|
|
|
for ( i in s.headers ) {
|
2011-02-11 06:07:06 +00:00
|
|
|
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
2011-01-16 01:57:39 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Allow custom headers/mimetypes and early abort
|
2014-07-17 17:25:59 +00:00
|
|
|
if ( s.beforeSend &&
|
|
|
|
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
|
|
|
|
2012-11-29 16:28:16 +00:00
|
|
|
// Abort if not done already and return
|
|
|
|
return jqXHR.abort();
|
2011-02-04 21:29:10 +00:00
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
|
2012-07-11 13:46:21 +00:00
|
|
|
// aborting is no longer a cancellation
|
2012-04-02 00:04:46 +00:00
|
|
|
strAbort = "abort";
|
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Install callbacks on deferreds
|
2015-02-15 02:41:38 +00:00
|
|
|
completeDeferred.add( s.complete );
|
|
|
|
jqXHR.done( s.success );
|
|
|
|
jqXHR.fail( s.error );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Get transport
|
|
|
|
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// If no transport, we auto-abort
|
|
|
|
if ( !transport ) {
|
|
|
|
done( -1, "No Transport" );
|
|
|
|
} else {
|
2011-02-07 15:35:32 +00:00
|
|
|
jqXHR.readyState = 1;
|
2012-11-23 15:29:08 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Send global event
|
|
|
|
if ( fireGlobals ) {
|
|
|
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
|
|
|
}
|
2014-07-13 17:53:00 +00:00
|
|
|
|
|
|
|
// If request was aborted inside ajaxSend, stop there
|
|
|
|
if ( state === 2 ) {
|
|
|
|
return jqXHR;
|
|
|
|
}
|
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Timeout
|
|
|
|
if ( s.async && s.timeout > 0 ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
timeoutTimer = window.setTimeout( function() {
|
|
|
|
jqXHR.abort( "timeout" );
|
2011-02-04 21:29:10 +00:00
|
|
|
}, s.timeout );
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
try {
|
2011-02-07 15:35:32 +00:00
|
|
|
state = 1;
|
2011-02-04 21:29:10 +00:00
|
|
|
transport.send( requestHeaders, done );
|
2012-11-23 15:29:08 +00:00
|
|
|
} catch ( e ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Propagate exception as error if not done
|
2011-06-30 16:18:44 +00:00
|
|
|
if ( state < 2 ) {
|
2011-11-08 18:12:37 +00:00
|
|
|
done( -1, e );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Simply rethrow otherwise
|
|
|
|
} else {
|
2011-11-08 18:12:37 +00:00
|
|
|
throw e;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-04 21:29:10 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Callback for when everything is done
|
|
|
|
function done( status, nativeStatusText, responses, headers ) {
|
|
|
|
var isSuccess, success, error, response, modified,
|
|
|
|
statusText = nativeStatusText;
|
|
|
|
|
|
|
|
// Called once
|
|
|
|
if ( state === 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// State is "done" now
|
|
|
|
state = 2;
|
|
|
|
|
|
|
|
// Clear timeout if it exists
|
|
|
|
if ( timeoutTimer ) {
|
2015-07-28 10:58:44 +00:00
|
|
|
window.clearTimeout( timeoutTimer );
|
2012-11-23 15:29:08 +00: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;
|
|
|
|
|
2013-02-08 15:26:36 +00:00
|
|
|
// Determine if successful
|
|
|
|
isSuccess = status >= 200 && status < 300 || status === 304;
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Get response data
|
|
|
|
if ( responses ) {
|
|
|
|
response = ajaxHandleResponses( s, jqXHR, responses );
|
|
|
|
}
|
|
|
|
|
2013-02-08 15:26:36 +00:00
|
|
|
// Convert no matter what (that way responseXXX fields are always set)
|
|
|
|
response = ajaxConvert( s, response, jqXHR, isSuccess );
|
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// If successful, handle type chaining
|
2013-02-08 15:26:36 +00:00
|
|
|
if ( isSuccess ) {
|
2012-11-23 15:29:08 +00:00
|
|
|
|
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
|
|
if ( s.ifModified ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
modified = jqXHR.getResponseHeader( "Last-Modified" );
|
2012-11-23 15:29:08 +00:00
|
|
|
if ( modified ) {
|
2012-11-29 16:16:42 +00:00
|
|
|
jQuery.lastModified[ cacheURL ] = modified;
|
2012-11-23 15:29:08 +00:00
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
modified = jqXHR.getResponseHeader( "etag" );
|
2012-11-23 15:29:08 +00:00
|
|
|
if ( modified ) {
|
2012-11-29 16:16:42 +00:00
|
|
|
jQuery.etag[ cacheURL ] = modified;
|
2012-11-23 15:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:33:17 +00:00
|
|
|
// if no content
|
2013-05-23 00:11:37 +00:00
|
|
|
if ( status === 204 || s.type === "HEAD" ) {
|
2013-01-24 01:33:17 +00:00
|
|
|
statusText = "nocontent";
|
|
|
|
|
|
|
|
// if not modified
|
|
|
|
} else if ( status === 304 ) {
|
2012-11-23 15:29:08 +00:00
|
|
|
statusText = "notmodified";
|
|
|
|
|
2013-01-24 01:33:17 +00:00
|
|
|
// If we have data, let's convert it
|
2012-11-23 15:29:08 +00:00
|
|
|
} else {
|
2013-02-08 15:26:36 +00:00
|
|
|
statusText = response.state;
|
|
|
|
success = response.data;
|
|
|
|
error = response.error;
|
2012-11-23 15:29:08 +00:00
|
|
|
isSuccess = !error;
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// We extract error from statusText
|
|
|
|
// then normalize statusText and status for non-aborts
|
|
|
|
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 ] );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
// Handle the global AJAX counter
|
|
|
|
if ( !( --jQuery.active ) ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
2012-11-23 15:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-01 15:00:30 +00:00
|
|
|
return jqXHR;
|
2010-03-02 02:24:49 +00:00
|
|
|
},
|
2007-09-03 23:45:14 +00:00
|
|
|
|
2012-11-23 15:29:08 +00:00
|
|
|
getJSON: function( url, data, callback ) {
|
|
|
|
return jQuery.get( url, data, callback, "json" );
|
2012-12-02 05:14:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getScript: function( url, callback ) {
|
|
|
|
return jQuery.get( url, undefined, callback, "script" );
|
2012-11-23 15:29:08 +00:00
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2010-03-02 15:44:48 +00:00
|
|
|
|
2012-12-02 05:14:25 +00:00
|
|
|
jQuery.each( [ "get", "post" ], function( i, method ) {
|
|
|
|
jQuery[ method ] = function( url, data, callback, type ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-12-02 05:14:25 +00:00
|
|
|
// shift arguments if data argument was omitted
|
|
|
|
if ( jQuery.isFunction( data ) ) {
|
|
|
|
type = type || callback;
|
|
|
|
callback = data;
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
|
2015-01-06 03:00:12 +00:00
|
|
|
// The url can be an options object (which then must have .url)
|
2015-09-02 23:52:01 +00:00
|
|
|
return jQuery.ajax( jQuery.extend( {
|
2012-12-02 05:14:25 +00:00
|
|
|
url: url,
|
|
|
|
type: method,
|
|
|
|
dataType: type,
|
|
|
|
data: data,
|
|
|
|
success: callback
|
2015-01-06 03:00:12 +00:00
|
|
|
}, jQuery.isPlainObject( url ) && url ) );
|
2012-12-02 05:14:25 +00:00
|
|
|
};
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-12-02 05:14:25 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
return jQuery;
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|