2010-09-08 17:54:33 +00:00
|
|
|
(function( jQuery ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
var r20 = /%20/g,
|
2010-09-22 13:16:28 +00:00
|
|
|
rbracket = /\[\]$/,
|
2011-01-22 03:45:20 +00:00
|
|
|
rCRLF = /\r?\n/g,
|
2010-12-25 17:54:37 +00:00
|
|
|
rhash = /#.*$/,
|
2011-02-17 16:03:09 +00:00
|
|
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
|
2011-07-07 10:13:10 +00:00
|
|
|
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
2011-02-03 04:19:15 +00:00
|
|
|
// #7653, #8125, #8152: local protocol detection
|
2011-07-01 00:18:05 +00:00
|
|
|
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,
|
2010-12-25 17:54:37 +00:00
|
|
|
rnoContent = /^(?:GET|HEAD)$/,
|
2011-01-26 00:36:05 +00:00
|
|
|
rprotocol = /^\/\//,
|
2009-07-19 19:44:15 +00:00
|
|
|
rquery = /\?/,
|
2010-12-25 17:54:37 +00:00
|
|
|
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
|
|
rselectTextarea = /^(?:select|textarea)/i,
|
2011-04-29 02:24:40 +00:00
|
|
|
rspacesAjax = /\s+/,
|
2010-12-25 17:54:37 +00:00
|
|
|
rts = /([?&])_=[^&]*/,
|
2011-03-15 18:20:03 +00:00
|
|
|
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-02-11 06:23:13 +00:00
|
|
|
// Keep a copy of the old load method
|
2011-01-22 03:45:20 +00:00
|
|
|
_load = jQuery.fn.load,
|
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
2011-01-22 03:45:20 +00:00
|
|
|
prefilters = {},
|
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
2011-02-02 19:52:26 +00:00
|
|
|
transports = {},
|
|
|
|
|
2011-02-03 01:53:10 +00:00
|
|
|
// Document location
|
|
|
|
ajaxLocation,
|
|
|
|
|
|
|
|
// Document location segments
|
2011-08-23 02:32:06 +00:00
|
|
|
ajaxLocParts,
|
2011-09-12 15:37:41 +00:00
|
|
|
|
2011-08-23 02:32:06 +00:00
|
|
|
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
2011-08-23 12:55:41 +00:00
|
|
|
allTypes = ["*/"] + ["*"];
|
2011-02-02 19:52:26 +00:00
|
|
|
|
|
|
|
// #8138, IE may throw an exception when accessing
|
2011-04-16 21:18:56 +00:00
|
|
|
// a field from window.location if document.domain has been set
|
2011-02-02 19:52:26 +00:00
|
|
|
try {
|
2011-04-16 21:18:56 +00:00
|
|
|
ajaxLocation = location.href;
|
2011-02-02 19:52:26 +00:00
|
|
|
} catch( e ) {
|
|
|
|
// Use the href attribute of an A element
|
|
|
|
// since IE will modify it given document.location
|
|
|
|
ajaxLocation = document.createElement( "a" );
|
|
|
|
ajaxLocation.href = "";
|
|
|
|
ajaxLocation = ajaxLocation.href;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2011-02-03 01:53:10 +00:00
|
|
|
// Segment location into parts
|
2011-03-15 18:20:03 +00:00
|
|
|
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
|
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 = "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( jQuery.isFunction( func ) ) {
|
2011-04-29 02:24:40 +00:00
|
|
|
var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ),
|
2011-01-23 21:03:24 +00:00
|
|
|
i = 0,
|
|
|
|
length = dataTypes.length,
|
|
|
|
dataType,
|
|
|
|
list,
|
|
|
|
placeBefore;
|
|
|
|
|
|
|
|
// For each dataType in the dataTypeExpression
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( ; i < length; i++ ) {
|
2011-01-23 21:03:24 +00:00
|
|
|
dataType = dataTypes[ i ];
|
|
|
|
// We control if we're asked to add before
|
|
|
|
// any existing element
|
|
|
|
placeBefore = /^\+/.test( dataType );
|
|
|
|
if ( placeBefore ) {
|
2011-01-31 09:13:54 +00:00
|
|
|
dataType = dataType.substr( 1 ) || "*";
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
|
|
|
list = structure[ dataType ] = structure[ dataType ] || [];
|
|
|
|
// then we add to the structure accordingly
|
|
|
|
list[ placeBefore ? "unshift" : "push" ]( func );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-04-19 07:29:20 +00:00
|
|
|
// Base inspection function for prefilters and transports
|
2011-02-01 15:00:30 +00:00
|
|
|
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
|
2011-01-24 03:22:46 +00:00
|
|
|
dataType /* internal */, inspected /* internal */ ) {
|
2011-01-23 21:03:24 +00:00
|
|
|
|
|
|
|
dataType = dataType || options.dataTypes[ 0 ];
|
2011-01-24 03:22:46 +00:00
|
|
|
inspected = inspected || {};
|
2011-01-23 21:03:24 +00:00
|
|
|
|
2011-01-24 03:22:46 +00:00
|
|
|
inspected[ dataType ] = true;
|
2011-01-23 21:03:24 +00:00
|
|
|
|
|
|
|
var list = structure[ dataType ],
|
|
|
|
i = 0,
|
|
|
|
length = list ? list.length : 0,
|
2011-01-24 03:22:46 +00:00
|
|
|
executeOnly = ( structure === prefilters ),
|
|
|
|
selection;
|
|
|
|
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( ; i < length && ( executeOnly || !selection ); i++ ) {
|
2011-02-01 15:00:30 +00:00
|
|
|
selection = list[ i ]( options, originalOptions, jqXHR );
|
2011-01-24 03:22:46 +00:00
|
|
|
// If we got redirected to another dataType
|
2011-02-04 20:50:18 +00:00
|
|
|
// we try there if executing only and not done already
|
2011-01-24 03:22:46 +00:00
|
|
|
if ( typeof selection === "string" ) {
|
2011-02-04 20:50:18 +00:00
|
|
|
if ( !executeOnly || inspected[ selection ] ) {
|
2011-01-24 03:22:46 +00:00
|
|
|
selection = undefined;
|
|
|
|
} else {
|
|
|
|
options.dataTypes.unshift( selection );
|
|
|
|
selection = inspectPrefiltersOrTransports(
|
2011-02-01 15:00:30 +00:00
|
|
|
structure, options, originalOptions, jqXHR, selection, inspected );
|
2011-01-24 03:22:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
|
|
|
// If we're only executing or nothing was selected
|
|
|
|
// we try the catchall dataType if not done already
|
2011-01-24 03:22:46 +00:00
|
|
|
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
|
|
|
|
selection = inspectPrefiltersOrTransports(
|
2011-02-01 15:00:30 +00:00
|
|
|
structure, options, originalOptions, jqXHR, "*", inspected );
|
2011-01-23 21:03:24 +00:00
|
|
|
}
|
|
|
|
// unnecessary when only executing (prefilters)
|
|
|
|
// but it'll be ignored by the caller in that case
|
2011-01-24 03:22:46 +00:00
|
|
|
return selection;
|
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 ) {
|
|
|
|
var key, deep,
|
|
|
|
flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( key in src ) {
|
2011-07-23 00:10:17 +00:00
|
|
|
if ( src[ key ] !== undefined ) {
|
|
|
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( deep ) {
|
|
|
|
jQuery.extend( true, target, deep );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-11 06:23:13 +00:00
|
|
|
jQuery.fn.extend({
|
2007-09-04 02:55:38 +00:00
|
|
|
load: function( url, params, callback ) {
|
2010-02-27 14:02:13 +00:00
|
|
|
if ( typeof url !== "string" && _load ) {
|
|
|
|
return _load.apply( this, arguments );
|
2009-11-11 19:55:32 +00:00
|
|
|
|
|
|
|
// Don't do a request if no elements are being requested
|
|
|
|
} else if ( !this.length ) {
|
|
|
|
return this;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
var off = url.indexOf( " " );
|
2007-08-25 03:55:12 +00:00
|
|
|
if ( off >= 0 ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
var selector = url.slice( off, url.length );
|
|
|
|
url = url.slice( 0, off );
|
2007-08-25 03:55:12 +00:00
|
|
|
}
|
2007-08-25 03:33:08 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
// Default to a GET request
|
|
|
|
var type = "GET";
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
// If the second parameter was provided
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( params ) {
|
2006-09-30 14:32:49 +00:00
|
|
|
// If it's a function
|
2007-01-16 11:38:33 +00:00
|
|
|
if ( jQuery.isFunction( params ) ) {
|
2006-09-30 14:32:49 +00:00
|
|
|
// We assume that it's the callback
|
|
|
|
callback = params;
|
2011-02-15 20:47:52 +00:00
|
|
|
params = undefined;
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
// Otherwise, build a param string
|
2009-07-19 19:37:11 +00:00
|
|
|
} else if ( typeof params === "object" ) {
|
2009-12-22 13:09:56 +00:00
|
|
|
params = jQuery.param( params, jQuery.ajaxSettings.traditional );
|
2006-09-30 14:32:49 +00:00
|
|
|
type = "POST";
|
|
|
|
}
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-01-25 02:58:32 +00:00
|
|
|
var self = this;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
// Request the remote document
|
2006-11-03 11:30:57 +00:00
|
|
|
jQuery.ajax({
|
|
|
|
url: url,
|
|
|
|
type: type,
|
2007-12-14 17:06:41 +00:00
|
|
|
dataType: "html",
|
2006-11-03 11:30:57 +00:00
|
|
|
data: params,
|
2011-01-11 19:02:33 +00:00
|
|
|
// Complete callback (responseText is used internally)
|
2011-02-01 15:00:30 +00:00
|
|
|
complete: function( jqXHR, status, responseText ) {
|
|
|
|
// Store the response as specified by the jqXHR object
|
|
|
|
responseText = jqXHR.responseText;
|
2007-07-20 21:59:52 +00:00
|
|
|
// If successful, inject the HTML into all the matched elements
|
2011-02-01 15:00:30 +00:00
|
|
|
if ( jqXHR.isResolved() ) {
|
2011-01-11 19:02:33 +00:00
|
|
|
// #4825: Get the actual response in case
|
|
|
|
// a dataFilter is present in ajaxSettings
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR.done(function( r ) {
|
2011-01-11 19:02:33 +00:00
|
|
|
responseText = r;
|
|
|
|
});
|
2007-08-25 03:33:08 +00:00
|
|
|
// See if a selector was specified
|
2010-01-25 02:58:32 +00:00
|
|
|
self.html( selector ?
|
2007-08-25 03:33:08 +00:00
|
|
|
// Create a dummy div to hold the results
|
2010-09-22 13:16:28 +00:00
|
|
|
jQuery("<div>")
|
2007-08-25 03:33:08 +00:00
|
|
|
// inject the contents of the document in, removing the scripts
|
|
|
|
// to avoid any 'Permission Denied' errors in IE
|
2011-01-11 19:02:33 +00:00
|
|
|
.append(responseText.replace(rscript, ""))
|
2007-08-25 03:33:08 +00:00
|
|
|
|
|
|
|
// Locate the specified elements
|
|
|
|
.find(selector) :
|
|
|
|
|
|
|
|
// If not, just inject the full result
|
2011-01-11 19:02:33 +00:00
|
|
|
responseText );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2007-07-20 21:59:52 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( callback ) {
|
2011-02-01 15:00:30 +00:00
|
|
|
self.each( callback, [ responseText, status, jqXHR ] );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-03 11:30:57 +00:00
|
|
|
}
|
|
|
|
});
|
2009-07-19 19:37:11 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
return this;
|
|
|
|
},
|
2006-05-16 16:18:52 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
serialize: function() {
|
2011-01-23 04:51:41 +00:00
|
|
|
return jQuery.param( this.serializeArray() );
|
2007-09-05 17:06:05 +00:00
|
|
|
},
|
2010-03-02 15:44:48 +00:00
|
|
|
|
2007-09-09 18:29:15 +00:00
|
|
|
serializeArray: function() {
|
2010-12-09 18:34:28 +00:00
|
|
|
return this.map(function(){
|
2011-01-23 04:51:41 +00:00
|
|
|
return this.elements ? jQuery.makeArray( this.elements ) : this;
|
2007-09-05 17:06:05 +00:00
|
|
|
})
|
2010-12-09 18:34:28 +00:00
|
|
|
.filter(function(){
|
2008-05-13 01:45:58 +00:00
|
|
|
return this.name && !this.disabled &&
|
2011-01-23 04:51:41 +00:00
|
|
|
( this.checked || rselectTextarea.test( this.nodeName ) ||
|
|
|
|
rinput.test( this.type ) );
|
2007-09-05 17:06:05 +00:00
|
|
|
})
|
2011-01-23 04:51:41 +00:00
|
|
|
.map(function( i, elem ){
|
|
|
|
var val = jQuery( this ).val();
|
2009-07-19 19:37:11 +00:00
|
|
|
|
|
|
|
return val == null ?
|
|
|
|
null :
|
2011-01-23 04:51:41 +00:00
|
|
|
jQuery.isArray( val ) ?
|
|
|
|
jQuery.map( val, function( val, i ){
|
|
|
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
2007-09-05 17:06:05 +00:00
|
|
|
}) :
|
2011-01-23 04:51:41 +00:00
|
|
|
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
2007-09-09 18:29:15 +00:00
|
|
|
}).get();
|
|
|
|
}
|
2006-09-30 14:32:49 +00:00
|
|
|
});
|
2006-09-08 10:18:46 +00:00
|
|
|
|
2006-06-19 01:29:54 +00:00
|
|
|
// Attach a bunch of functions for handling common AJAX events
|
2011-01-23 04:51:41 +00:00
|
|
|
jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split( " " ), function( i, o ){
|
|
|
|
jQuery.fn[ o ] = function( f ){
|
|
|
|
return this.bind( o, f );
|
2006-08-17 04:18:32 +00:00
|
|
|
};
|
2011-04-08 15:41:14 +00:00
|
|
|
});
|
$.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
|
|
|
|
2010-12-26 22:49:01 +00:00
|
|
|
jQuery.each( [ "get", "post" ], function( i, method ) {
|
|
|
|
jQuery[ method ] = function( url, data, callback, type ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
// shift arguments if data argument was omitted
|
2007-01-14 06:22:20 +00:00
|
|
|
if ( jQuery.isFunction( data ) ) {
|
2009-09-15 16:45:37 +00:00
|
|
|
type = type || callback;
|
2006-07-10 03:20:56 +00:00
|
|
|
callback = data;
|
2011-02-15 20:47:52 +00:00
|
|
|
data = undefined;
|
2006-07-10 03:20:56 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2006-12-15 09:13:24 +00:00
|
|
|
return jQuery.ajax({
|
2010-12-26 18:51:29 +00:00
|
|
|
type: method,
|
2006-11-03 11:30:57 +00:00
|
|
|
url: url,
|
2006-11-11 11:34:51 +00:00
|
|
|
data: data,
|
|
|
|
success: callback,
|
2007-09-04 02:55:38 +00:00
|
|
|
dataType: type
|
2006-11-03 11:30:57 +00:00
|
|
|
});
|
2010-12-26 18:51:29 +00:00
|
|
|
};
|
2011-04-08 15:41:14 +00:00
|
|
|
});
|
2010-12-26 18:51:29 +00:00
|
|
|
|
|
|
|
jQuery.extend({
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
getScript: function( url, callback ) {
|
2011-02-15 20:47:52 +00:00
|
|
|
return jQuery.get( url, undefined, callback, "script" );
|
2006-09-08 10:18:46 +00:00
|
|
|
},
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-09-08 10:18:46 +00:00
|
|
|
getJSON: function( url, data, callback ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
return jQuery.get( url, data, callback, "json" );
|
2006-07-10 03:20:56 +00:00
|
|
|
},
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2011-02-12 02:59:46 +00:00
|
|
|
// Creates a full fledged settings object into target
|
|
|
|
// with both ajaxSettings and settings fields.
|
|
|
|
// If target is omitted, writes into ajaxSettings.
|
2011-07-23 00:10:17 +00:00
|
|
|
ajaxSetup: function( target, settings ) {
|
|
|
|
if ( settings ) {
|
|
|
|
// Building a settings object
|
|
|
|
ajaxExtend( target, jQuery.ajaxSettings );
|
2011-02-12 02:59:46 +00:00
|
|
|
} else {
|
2011-07-23 00:10:17 +00:00
|
|
|
// Extending ajaxSettings
|
|
|
|
settings = target;
|
|
|
|
target = jQuery.ajaxSettings;
|
2011-02-12 02:59:46 +00:00
|
|
|
}
|
2011-07-23 00:10:17 +00:00
|
|
|
ajaxExtend( target, settings );
|
2011-02-12 02:59:46 +00:00
|
|
|
return target;
|
2006-08-17 04:18:32 +00:00
|
|
|
},
|
|
|
|
|
2006-12-22 13:56:36 +00:00
|
|
|
ajaxSettings: {
|
2011-02-02 19:52:26 +00:00
|
|
|
url: ajaxLocation,
|
2011-02-03 01:53:10 +00:00
|
|
|
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
|
2006-12-22 13:56:36 +00:00
|
|
|
global: true,
|
|
|
|
type: "GET",
|
|
|
|
contentType: "application/x-www-form-urlencoded",
|
|
|
|
processData: true,
|
2007-01-14 22:51:55 +00:00
|
|
|
async: true,
|
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,
|
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: {
|
|
|
|
xml: "application/xml, text/xml",
|
|
|
|
html: "text/html",
|
|
|
|
text: "text/plain",
|
2010-12-09 18:34:28 +00:00
|
|
|
json: "application/json, text/javascript",
|
2011-08-23 12:47:34 +00:00
|
|
|
"*": allTypes
|
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",
|
|
|
|
text: "responseText"
|
|
|
|
},
|
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// List of data converters
|
2010-12-24 17:02:45 +00:00
|
|
|
// 1) key format is "source_type destination_type" (a single space in-between)
|
2010-12-09 18:34:28 +00:00
|
|
|
// 2) the catchall symbol "*" can be used for source_type
|
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
|
2010-12-24 17:02:45 +00:00
|
|
|
"* text": window.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: {
|
|
|
|
context: true,
|
|
|
|
url: 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
|
|
|
|
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
|
|
|
|
2011-01-19 16:06:33 +00:00
|
|
|
var // Create the final options object
|
2011-02-12 02:59:46 +00:00
|
|
|
s = jQuery.ajaxSetup( {}, options ),
|
2011-01-31 16:23:36 +00:00
|
|
|
// Callbacks context
|
2011-02-12 02:59:46 +00:00
|
|
|
callbackContext = s.context || s,
|
2011-01-31 16:23:36 +00:00
|
|
|
// Context for global events
|
|
|
|
// It's the callbackContext if one was provided in the options
|
2011-02-07 16:09:47 +00:00
|
|
|
// and if it's a DOM node or a jQuery collection
|
|
|
|
globalEventContext = callbackContext !== s &&
|
|
|
|
( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
|
|
|
|
jQuery( callbackContext ) : jQuery.event,
|
2010-12-25 17:54:37 +00:00
|
|
|
// Deferreds
|
|
|
|
deferred = jQuery.Deferred(),
|
2011-09-12 15:37:41 +00:00
|
|
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode = s.statusCode || {},
|
2011-01-31 18:59:53 +00:00
|
|
|
// ifModified key
|
|
|
|
ifModifiedKey,
|
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 = {},
|
2010-12-25 17:54:37 +00:00
|
|
|
// Response headers
|
|
|
|
responseHeadersString,
|
|
|
|
responseHeaders,
|
|
|
|
// transport
|
|
|
|
transport,
|
|
|
|
// timeout handle
|
|
|
|
timeoutTimer,
|
2011-01-12 23:41:10 +00:00
|
|
|
// Cross-domain detection vars
|
|
|
|
parts,
|
2011-02-01 15:00:30 +00:00
|
|
|
// The jqXHR state
|
2010-12-25 17:54:37 +00:00
|
|
|
state = 0,
|
2011-02-04 21:19:23 +00:00
|
|
|
// To know if global events are to be dispatched
|
|
|
|
fireGlobals,
|
2010-12-25 17:54:37 +00:00
|
|
|
// Loop variable
|
|
|
|
i,
|
|
|
|
// Fake xhr
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR = {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
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
|
|
|
// Caches the header
|
2011-01-23 04:51:41 +00:00
|
|
|
setRequestHeader: function( name, value ) {
|
2011-02-11 06:07:06 +00:00
|
|
|
if ( !state ) {
|
2011-04-19 07:29:20 +00:00
|
|
|
var lname = name.toLowerCase();
|
|
|
|
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
|
|
|
|
requestHeaders[ name ] = value;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Raw string
|
|
|
|
getAllResponseHeaders: function() {
|
|
|
|
return state === 2 ? responseHeadersString : null;
|
|
|
|
},
|
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 = {};
|
2011-01-19 16:21:51 +00:00
|
|
|
while( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
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
|
|
|
}
|
2011-02-17 16:03:09 +00:00
|
|
|
return match === undefined ? null : match;
|
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;
|
|
|
|
},
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Cancel the request
|
|
|
|
abort: function( statusText ) {
|
2011-01-25 15:08:19 +00:00
|
|
|
statusText = statusText || "abort";
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( transport ) {
|
2011-01-25 15:08:19 +00:00
|
|
|
transport.abort( statusText );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-23 04:51:41 +00:00
|
|
|
done( 0, statusText );
|
2010-12-25 17:54:37 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Callback for when everything is done
|
|
|
|
// It is defined here because jslint complains if it is declared
|
|
|
|
// at the end of the function (which would be more logical and readable)
|
2011-07-23 00:39:12 +00:00
|
|
|
function done( status, nativeStatusText, responses, headers ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Called once
|
|
|
|
if ( state === 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// State is "done" now
|
|
|
|
state = 2;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-22 03:45:20 +00:00
|
|
|
// Clear timeout if it exists
|
|
|
|
if ( timeoutTimer ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
clearTimeout( timeoutTimer );
|
2011-01-22 03:45:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Dereference transport for early garbage collection
|
2011-02-01 15:00:30 +00:00
|
|
|
// (no matter how long the jqXHR object will be used)
|
2011-01-19 16:24:56 +00:00
|
|
|
transport = undefined;
|
2011-01-16 01:57:39 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Cache response headers
|
|
|
|
responseHeadersString = headers || "";
|
|
|
|
|
2011-01-22 03:45:20 +00:00
|
|
|
// Set readyState
|
2011-07-23 00:17:46 +00:00
|
|
|
jqXHR.readyState = status > 0 ? 4 : 0;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-22 03:45:20 +00:00
|
|
|
var isSuccess,
|
2010-12-25 17:54:37 +00:00
|
|
|
success,
|
2011-01-25 15:08:19 +00:00
|
|
|
error,
|
2011-07-23 00:39:12 +00:00
|
|
|
statusText = nativeStatusText,
|
2011-02-01 15:00:30 +00:00
|
|
|
response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
|
2011-01-22 03:45:20 +00:00
|
|
|
lastModified,
|
|
|
|
etag;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// If successful, handle type chaining
|
2011-01-13 00:43:42 +00:00
|
|
|
if ( status >= 200 && status < 300 || status === 304 ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
|
|
|
if ( s.ifModified ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-01 15:00:30 +00:00
|
|
|
if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
|
2011-01-31 18:59:53 +00:00
|
|
|
jQuery.lastModified[ ifModifiedKey ] = lastModified;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-02-01 15:00:30 +00:00
|
|
|
if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
|
2011-01-31 18:59:53 +00:00
|
|
|
jQuery.etag[ ifModifiedKey ] = etag;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
// If not modified
|
|
|
|
if ( status === 304 ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
statusText = "notmodified";
|
2011-01-22 03:45:20 +00:00
|
|
|
isSuccess = true;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
// If we have data
|
2010-12-25 17:54:37 +00:00
|
|
|
} else {
|
2011-01-13 00:43:42 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
try {
|
2011-01-23 04:51:41 +00:00
|
|
|
success = ajaxConvert( s, response );
|
2011-01-22 03:45:20 +00:00
|
|
|
statusText = "success";
|
|
|
|
isSuccess = true;
|
2010-12-25 17:54:37 +00:00
|
|
|
} catch(e) {
|
2011-01-13 00:43:42 +00:00
|
|
|
// We have a parsererror
|
2010-12-25 17:54:37 +00:00
|
|
|
statusText = "parsererror";
|
2011-11-08 17:49:58 +00:00
|
|
|
error = e;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 15:08:19 +00:00
|
|
|
} else {
|
|
|
|
// We extract error from statusText
|
|
|
|
// then normalize statusText and status for non-aborts
|
|
|
|
error = statusText;
|
2011-10-26 18:58:05 +00:00
|
|
|
if ( !statusText || status ) {
|
2011-01-25 15:08:19 +00:00
|
|
|
statusText = "error";
|
|
|
|
if ( status < 0 ) {
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Set data for the fake xhr object
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR.status = status;
|
2011-07-23 00:39:12 +00:00
|
|
|
jqXHR.statusText = "" + ( nativeStatusText || statusText );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Success/Error
|
|
|
|
if ( isSuccess ) {
|
2011-02-01 15:00:30 +00:00
|
|
|
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
} else {
|
2011-02-01 15:00:30 +00:00
|
|
|
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR.statusCode( statusCode );
|
2011-01-20 14:39:30 +00:00
|
|
|
statusCode = undefined;
|
2011-01-13 16:01:25 +00:00
|
|
|
|
2011-02-04 21:19:23 +00:00
|
|
|
if ( fireGlobals ) {
|
2011-01-23 19:46:09 +00:00
|
|
|
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
|
2011-02-01 15:00:30 +00:00
|
|
|
[ jqXHR, s, isSuccess ? success : error ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Complete
|
2011-09-12 15:37:41 +00:00
|
|
|
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-02-04 21:19:23 +00:00
|
|
|
if ( fireGlobals ) {
|
2011-07-23 00:10:17 +00:00
|
|
|
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
// Handle the global AJAX counter
|
2011-01-23 21:03:24 +00:00
|
|
|
if ( !( --jQuery.active ) ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-28 03:13:44 +00:00
|
|
|
// Attach deferreds
|
2011-02-01 15:00:30 +00:00
|
|
|
deferred.promise( jqXHR );
|
|
|
|
jqXHR.success = jqXHR.done;
|
|
|
|
jqXHR.error = jqXHR.fail;
|
2011-09-12 15:37:41 +00:00
|
|
|
jqXHR.complete = completeDeferred.add;
|
2010-12-25 17:54:37 +00:00
|
|
|
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR.statusCode = function( map ) {
|
2011-01-13 16:01:25 +00:00
|
|
|
if ( map ) {
|
2011-01-19 16:51:33 +00:00
|
|
|
var tmp;
|
2011-01-22 03:45:20 +00:00
|
|
|
if ( state < 2 ) {
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( tmp in map ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
|
2011-01-13 16:01:25 +00:00
|
|
|
}
|
2011-01-19 16:51:33 +00:00
|
|
|
} else {
|
2011-02-01 15:00:30 +00:00
|
|
|
tmp = map[ jqXHR.status ];
|
|
|
|
jqXHR.then( tmp, tmp );
|
2011-01-13 16:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Remove hash character (#7531: and string promotion)
|
2011-01-26 00:45:00 +00:00
|
|
|
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
|
2011-01-20 15:22:36 +00:00
|
|
|
// We also use the url parameter if available
|
2011-02-12 02:59:46 +00:00
|
|
|
s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Extract dataTypes list
|
2011-04-29 02:24:40 +00:00
|
|
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Determine if a cross-domain request is in order
|
2011-03-10 23:17:38 +00:00
|
|
|
if ( s.crossDomain == null ) {
|
2011-01-12 23:41:10 +00:00
|
|
|
parts = rurl.exec( s.url.toLowerCase() );
|
2011-01-26 00:36:05 +00:00
|
|
|
s.crossDomain = !!( parts &&
|
2011-02-03 01:53:10 +00:00
|
|
|
( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
|
2011-01-26 00:36:05 +00:00
|
|
|
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
|
2011-02-03 01:53:10 +00:00
|
|
|
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
|
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
|
|
|
|
2011-02-04 21:19:23 +00:00
|
|
|
// If request was aborted inside a prefiler, stop there
|
|
|
|
if ( state === 2 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can fire global events as of now if asked to
|
|
|
|
fireGlobals = s.global;
|
|
|
|
|
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
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Watch for a new set of requests
|
2011-02-04 21:19:23 +00:00
|
|
|
if ( fireGlobals && jQuery.active++ === 0 ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
jQuery.event.trigger( "ajaxStart" );
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
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 ) {
|
|
|
|
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
|
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-31 18:59:53 +00:00
|
|
|
// Get ifModifiedKey before adding the anti-cache parameter
|
|
|
|
ifModifiedKey = s.url;
|
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Add anti-cache in url if needed
|
|
|
|
if ( s.cache === false ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
var ts = jQuery.now(),
|
|
|
|
// try replacing _= if it is there
|
2011-01-23 04:51:41 +00:00
|
|
|
ret = s.url.replace( rts, "$1_=" + ts );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// if nothing was replaced, add timestamp to the end
|
2011-10-27 19:26:37 +00:00
|
|
|
s.url = ret + ( ( ret === s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "" );
|
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 correct header, if data is being sent
|
|
|
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
2011-04-15 20:36:43 +00:00
|
|
|
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
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 ) {
|
2011-01-31 18:59:53 +00:00
|
|
|
ifModifiedKey = ifModifiedKey || s.url;
|
|
|
|
if ( jQuery.lastModified[ ifModifiedKey ] ) {
|
2011-04-15 20:36:43 +00:00
|
|
|
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-31 18:59:53 +00:00
|
|
|
if ( jQuery.etag[ ifModifiedKey ] ) {
|
2011-04-15 20:36:43 +00:00
|
|
|
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
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 Accepts header for the server, depending on the dataType
|
2011-04-15 21:16:43 +00:00
|
|
|
jqXHR.setRequestHeader(
|
|
|
|
"Accept",
|
|
|
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
2011-08-23 12:47:34 +00:00
|
|
|
s.accepts[ s.dataTypes[0] ] + ( 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
|
2011-02-01 15:00:30 +00:00
|
|
|
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
2011-01-16 01:57:39 +00:00
|
|
|
// Abort if not done already
|
2011-02-04 21:29:10 +00:00
|
|
|
jqXHR.abort();
|
|
|
|
return false;
|
2011-01-16 01:57:39 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
|
2011-02-04 21:29:10 +00:00
|
|
|
// Install callbacks on deferreds
|
|
|
|
for ( i in { success: 1, error: 1, complete: 1 } ) {
|
|
|
|
jqXHR[ i ]( s[ i ] );
|
|
|
|
}
|
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;
|
2011-02-04 21:29:10 +00:00
|
|
|
// Send global event
|
|
|
|
if ( fireGlobals ) {
|
|
|
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
|
|
|
}
|
|
|
|
// Timeout
|
|
|
|
if ( s.async && s.timeout > 0 ) {
|
|
|
|
timeoutTimer = setTimeout( function(){
|
|
|
|
jqXHR.abort( "timeout" );
|
|
|
|
}, 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 );
|
|
|
|
} catch (e) {
|
|
|
|
// Propagate exception as error if not done
|
2011-06-30 16:18:44 +00:00
|
|
|
if ( state < 2 ) {
|
2011-11-08 14:42:08 +00:00
|
|
|
done( -1, e.message );
|
2011-02-04 21:29:10 +00:00
|
|
|
// Simply rethrow otherwise
|
|
|
|
} else {
|
2011-11-08 14:42:08 +00:00
|
|
|
jQuery.error( e.message );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-04 21:29:10 +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
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
// Serialize an array of form elements or a set of
|
|
|
|
// key/values into a query string
|
|
|
|
param: function( a, traditional ) {
|
2010-11-09 16:09:07 +00:00
|
|
|
var s = [],
|
|
|
|
add = function( key, value ) {
|
|
|
|
// If value is a function, invoke it and return its value
|
2011-01-23 04:51:41 +00:00
|
|
|
value = jQuery.isFunction( value ) ? value() : value;
|
|
|
|
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
2010-11-09 16:09:07 +00:00
|
|
|
};
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
// Set traditional to true for jQuery <= 1.3.2 behavior.
|
|
|
|
if ( traditional === undefined ) {
|
|
|
|
traditional = jQuery.ajaxSettings.traditional;
|
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
// If an array was passed in, assume that it is an array of form elements.
|
2011-02-01 23:32:29 +00:00
|
|
|
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
// Serialize the form elements
|
|
|
|
jQuery.each( a, function() {
|
|
|
|
add( this.name, this.value );
|
2011-04-08 15:41:14 +00:00
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
} else {
|
|
|
|
// If traditional, encode the "old" way (the way 1.3.2 or older
|
|
|
|
// did it), otherwise encode params recursively.
|
|
|
|
for ( var prefix in a ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
buildParams( prefix, a[ prefix ], traditional, add );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
// Return the resulting serialization
|
2011-01-23 04:51:41 +00:00
|
|
|
return s.join( "&" ).replace( r20, "+" );
|
2010-03-02 02:24:49 +00:00
|
|
|
}
|
|
|
|
});
|
2007-09-03 23:45:14 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
function buildParams( prefix, obj, traditional, add ) {
|
2011-04-16 16:12:53 +00:00
|
|
|
if ( jQuery.isArray( obj ) ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
// Serialize array item.
|
|
|
|
jQuery.each( obj, function( i, v ) {
|
2010-09-22 13:16:28 +00:00
|
|
|
if ( traditional || rbracket.test( prefix ) ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
// Treat each array item as a scalar.
|
|
|
|
add( prefix, v );
|
2007-09-03 23:45:14 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
} else {
|
|
|
|
// If array item is non-scalar (array or object), encode its
|
|
|
|
// numeric index to resolve deserialization ambiguity issues.
|
|
|
|
// Note that rack (as of 1.0.0) can't currently deserialize
|
|
|
|
// nested arrays properly, and attempting to do so may cause
|
|
|
|
// a server error. Possible fixes are to modify rack's
|
|
|
|
// deserialization algorithm or to provide an option or flag
|
|
|
|
// to force array serialization to be shallow.
|
|
|
|
buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2010-03-02 02:24:49 +00:00
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
} else if ( !traditional && obj != null && typeof obj === "object" ) {
|
|
|
|
// Serialize object item.
|
2011-04-16 16:12:53 +00:00
|
|
|
for ( var name in obj ) {
|
|
|
|
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
2010-09-24 20:57:25 +00:00
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
} else {
|
|
|
|
// Serialize scalar item.
|
|
|
|
add( prefix, obj );
|
|
|
|
}
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2010-10-11 22:29:52 +00:00
|
|
|
// This is still on the jQuery object... for now
|
|
|
|
// Want to move this to jQuery.ajax some day
|
|
|
|
jQuery.extend({
|
2010-03-02 02:24:49 +00:00
|
|
|
|
|
|
|
// Counter for holding the number of active queries
|
|
|
|
active: 0,
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2010-03-02 15:44:48 +00:00
|
|
|
// Last-Modified header cache for next request
|
|
|
|
lastModified: {},
|
2010-12-09 18:34:28 +00:00
|
|
|
etag: {}
|
2010-03-02 02:24:49 +00:00
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
});
|
2010-03-02 15:44:48 +00:00
|
|
|
|
2011-01-23 04:51:41 +00:00
|
|
|
/* Handles responses to an ajax request:
|
|
|
|
* - sets all responseXXX fields accordingly
|
|
|
|
* - finds the right dataType (mediates between content-type and expected dataType)
|
|
|
|
* - returns the corresponding response
|
|
|
|
*/
|
2011-02-01 15:00:30 +00:00
|
|
|
function ajaxHandleResponses( s, jqXHR, responses ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
|
|
|
|
var contents = s.contents,
|
|
|
|
dataTypes = s.dataTypes,
|
|
|
|
responseFields = s.responseFields,
|
|
|
|
ct,
|
|
|
|
type,
|
|
|
|
finalDataType,
|
|
|
|
firstDataType;
|
|
|
|
|
|
|
|
// Fill responseXXX fields
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( type in responseFields ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
if ( type in responses ) {
|
2011-02-01 15:00:30 +00:00
|
|
|
jqXHR[ responseFields[type] ] = responses[ type ];
|
2011-01-22 03:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove auto dataType and get content-type in the process
|
2011-01-23 04:51:41 +00:00
|
|
|
while( dataTypes[ 0 ] === "*" ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
dataTypes.shift();
|
|
|
|
if ( ct === undefined ) {
|
2011-02-09 16:47:33 +00:00
|
|
|
ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
|
2011-01-22 03:45:20 +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
|
2011-01-23 04:51:41 +00:00
|
|
|
if ( dataTypes[ 0 ] in responses ) {
|
|
|
|
finalDataType = dataTypes[ 0 ];
|
2011-01-22 03:45:20 +00:00
|
|
|
} else {
|
|
|
|
// Try convertible dataTypes
|
|
|
|
for ( type in responses ) {
|
2011-01-23 19:46:09 +00:00
|
|
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
finalDataType = type;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-23 19:46:09 +00:00
|
|
|
if ( !firstDataType ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
firstDataType = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Or just use first one
|
|
|
|
finalDataType = finalDataType || firstDataType;
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-22 03:45:20 +00:00
|
|
|
// If we found a dataType
|
|
|
|
// We add the dataType to the list if needed
|
|
|
|
// and return the corresponding response
|
|
|
|
if ( finalDataType ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
if ( finalDataType !== dataTypes[ 0 ] ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
dataTypes.unshift( finalDataType );
|
|
|
|
}
|
|
|
|
return responses[ finalDataType ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chain conversions given the request and the original response
|
2011-01-23 04:51:41 +00:00
|
|
|
function ajaxConvert( s, response ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
|
|
|
|
// Apply the dataFilter if provided
|
|
|
|
if ( s.dataFilter ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
response = s.dataFilter( response, s.dataType );
|
2011-01-22 03:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var dataTypes = s.dataTypes,
|
2011-01-31 16:39:54 +00:00
|
|
|
converters = {},
|
2011-01-22 03:45:20 +00:00
|
|
|
i,
|
2011-01-31 16:39:54 +00:00
|
|
|
key,
|
2011-01-22 03:45:20 +00:00
|
|
|
length = dataTypes.length,
|
|
|
|
tmp,
|
|
|
|
// Current and previous dataTypes
|
2011-01-23 04:51:41 +00:00
|
|
|
current = dataTypes[ 0 ],
|
2011-01-22 03:45:20 +00:00
|
|
|
prev,
|
|
|
|
// Conversion expression
|
|
|
|
conversion,
|
|
|
|
// Conversion function
|
|
|
|
conv,
|
2011-01-28 16:08:46 +00:00
|
|
|
// Conversion functions (transitive conversion)
|
2011-01-22 03:45:20 +00:00
|
|
|
conv1,
|
|
|
|
conv2;
|
|
|
|
|
|
|
|
// For each dataType in the chain
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( i = 1; i < length; i++ ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
|
2011-01-31 16:39:54 +00:00
|
|
|
// Create converters map
|
|
|
|
// with lowercased keys
|
|
|
|
if ( i === 1 ) {
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( key in s.converters ) {
|
|
|
|
if ( typeof key === "string" ) {
|
2011-01-31 16:39:54 +00:00
|
|
|
converters[ key.toLowerCase() ] = s.converters[ key ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-22 03:45:20 +00:00
|
|
|
// Get the dataTypes
|
|
|
|
prev = current;
|
|
|
|
current = dataTypes[ i ];
|
|
|
|
|
|
|
|
// If current is auto dataType, update it to prev
|
2011-10-26 18:58:05 +00:00
|
|
|
if ( current === "*" ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
current = prev;
|
|
|
|
// If no auto and dataTypes are actually different
|
|
|
|
} else if ( prev !== "*" && prev !== current ) {
|
|
|
|
|
|
|
|
// Get the converter
|
|
|
|
conversion = prev + " " + current;
|
|
|
|
conv = converters[ conversion ] || converters[ "* " + current ];
|
|
|
|
|
|
|
|
// If there is no direct converter, search transitively
|
2011-01-23 21:03:24 +00:00
|
|
|
if ( !conv ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
conv2 = undefined;
|
2011-10-26 18:58:05 +00:00
|
|
|
for ( conv1 in converters ) {
|
2011-01-22 03:45:20 +00:00
|
|
|
tmp = conv1.split( " " );
|
|
|
|
if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
conv2 = converters[ tmp[1] + " " + current ];
|
2011-01-22 03:45:20 +00:00
|
|
|
if ( conv2 ) {
|
|
|
|
conv1 = converters[ conv1 ];
|
|
|
|
if ( conv1 === true ) {
|
|
|
|
conv = conv2;
|
|
|
|
} else if ( conv2 === true ) {
|
|
|
|
conv = conv1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-22 03:45:20 +00:00
|
|
|
}
|
|
|
|
// If we found no converter, dispatch an error
|
2011-01-23 21:03:24 +00:00
|
|
|
if ( !( conv || conv2 ) ) {
|
2011-01-23 04:51:41 +00:00
|
|
|
jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
|
2011-01-22 03:45:20 +00:00
|
|
|
}
|
|
|
|
// If found converter is not an equivalence
|
|
|
|
if ( conv !== true ) {
|
|
|
|
// Convert with 1 or 2 converters accordingly
|
2011-01-23 04:51:41 +00:00
|
|
|
response = conv ? conv( response ) : conv2( conv1(response) );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-22 03:45:20 +00:00
|
|
|
return response;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 02:16:50 +00:00
|
|
|
})( jQuery );
|