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 = /\[\]$/,
|
2010-12-25 17:54:37 +00:00
|
|
|
rhash = /#.*$/,
|
|
|
|
rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
|
|
|
|
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
|
|
|
rnoContent = /^(?:GET|HEAD)$/,
|
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,
|
|
|
|
rts = /([?&])_=[^&]*/,
|
2011-01-09 05:01:00 +00:00
|
|
|
rurl = /^(\w+:)?\/\/([^\/?#:]+)(?::(\d+))?/,
|
2011-01-09 22:22:11 +00:00
|
|
|
rCRLF = /\r?\n/g,
|
2009-07-19 19:44:15 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Slice function
|
|
|
|
sliceFunc = Array.prototype.slice,
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-02-11 06:23:13 +00:00
|
|
|
// Keep a copy of the old load method
|
|
|
|
_load = jQuery.fn.load;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
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
|
|
|
|
2007-08-25 03:33:08 +00:00
|
|
|
var off = url.indexOf(" ");
|
2007-08-25 03:55:12 +00:00
|
|
|
if ( off >= 0 ) {
|
|
|
|
var selector = url.slice(off, url.length);
|
|
|
|
url = url.slice(0, off);
|
|
|
|
}
|
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;
|
|
|
|
params = null;
|
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)
|
|
|
|
complete: function( jXHR, status, responseText ) {
|
|
|
|
// Store the response as specified by the jXHR object
|
|
|
|
responseText = jXHR.responseText;
|
2007-07-20 21:59:52 +00:00
|
|
|
// If successful, inject the HTML into all the matched elements
|
2011-01-11 19:02:33 +00:00
|
|
|
if ( jXHR.isResolved() ) {
|
|
|
|
// #4825: Get the actual response in case
|
|
|
|
// a dataFilter is present in ajaxSettings
|
|
|
|
jXHR.done(function( r ) {
|
|
|
|
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-01-11 19:02:33 +00:00
|
|
|
self.each( callback, [responseText, status, jXHR] );
|
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() {
|
2007-09-05 17:06:05 +00:00
|
|
|
return jQuery.param(this.serializeArray());
|
|
|
|
},
|
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(){
|
2008-08-13 01:44:36 +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 &&
|
2009-07-19 19:44:15 +00:00
|
|
|
(this.checked || rselectTextarea.test(this.nodeName) ||
|
|
|
|
rinput.test(this.type));
|
2007-09-05 17:06:05 +00:00
|
|
|
})
|
2010-12-09 18:34:28 +00:00
|
|
|
.map(function(i, elem){
|
2007-09-09 18:29:15 +00:00
|
|
|
var val = jQuery(this).val();
|
2009-07-19 19:37:11 +00:00
|
|
|
|
|
|
|
return val == null ?
|
|
|
|
null :
|
2008-10-29 02:01:22 +00:00
|
|
|
jQuery.isArray(val) ?
|
2010-12-09 18:34:28 +00:00
|
|
|
jQuery.map( val, function(val, i){
|
2011-01-09 22:22:11 +00:00
|
|
|
return { name: elem.name, value: val.replace(rCRLF, "\r\n") };
|
2007-09-05 17:06:05 +00:00
|
|
|
}) :
|
2011-01-09 22:22:11 +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
|
2010-12-09 18:34:28 +00:00
|
|
|
jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "), function(i,o){
|
|
|
|
jQuery.fn[o] = function(f){
|
2007-01-06 05:31:47 +00:00
|
|
|
return this.bind(o, f);
|
2006-08-17 04:18:32 +00:00
|
|
|
};
|
2007-01-06 05:31:47 +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 ) {
|
2009-09-15 15:28:28 +00:00
|
|
|
// shift arguments if data argument was omited
|
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;
|
|
|
|
data = null;
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.extend({
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-09-30 14:32:49 +00:00
|
|
|
getScript: function( url, callback ) {
|
2006-12-15 09:13:24 +00:00
|
|
|
return jQuery.get(url, null, 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 ) {
|
2006-12-15 09:13:24 +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
|
|
|
|
2007-01-06 06:18:02 +00:00
|
|
|
ajaxSetup: function( settings ) {
|
2011-01-12 17:53:00 +00:00
|
|
|
jQuery.extend( true, jQuery.ajaxSettings, settings );
|
2011-01-13 17:33:24 +00:00
|
|
|
return this;
|
2006-08-17 04:18:32 +00:00
|
|
|
},
|
|
|
|
|
2006-12-22 13:56:36 +00:00
|
|
|
ajaxSettings: {
|
2008-05-14 19:50:24 +00:00
|
|
|
url: location.href,
|
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: {},
|
|
|
|
crossDomain: null,
|
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",
|
|
|
|
"*": "*/*"
|
|
|
|
},
|
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
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Prefilters
|
|
|
|
// 1) They are useful to introduce custom dataTypes (see transport/jsonp 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)
|
2010-12-21 12:06:41 +00:00
|
|
|
// 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: {},
|
2010-12-21 15:58:52 +00:00
|
|
|
|
2010-12-09 18:34:28 +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
|
2010-12-21 12:06:41 +00:00
|
|
|
transports: {},
|
2010-12-21 15:58:52 +00:00
|
|
|
|
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-01-19 17:16:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Utility function that handles dataType when response is received
|
|
|
|
// (for those transports that can give text or xml responses)
|
|
|
|
determineDataType: function( ct , text , xml ) {
|
|
|
|
|
|
|
|
var s = this,
|
|
|
|
contents = s.contents,
|
|
|
|
type,
|
|
|
|
regexp,
|
|
|
|
dataTypes = s.dataTypes,
|
|
|
|
transportDataType = dataTypes[0],
|
|
|
|
response;
|
|
|
|
|
|
|
|
// Auto (xml, json, script or text determined given headers)
|
|
|
|
if ( transportDataType === "*" ) {
|
|
|
|
|
|
|
|
for ( type in contents ) {
|
|
|
|
if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
|
|
|
|
transportDataType = dataTypes[0] = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// xml and parsed as such
|
|
|
|
if ( transportDataType === "xml" &&
|
|
|
|
xml &&
|
|
|
|
xml.documentElement /* #4958 */ ) {
|
|
|
|
|
|
|
|
response = xml;
|
|
|
|
|
|
|
|
// Text response was provided
|
|
|
|
} else {
|
|
|
|
|
|
|
|
response = text;
|
|
|
|
|
|
|
|
// If it's not really text, defer to converters
|
|
|
|
if ( transportDataType !== "text" ) {
|
|
|
|
dataTypes.unshift( "text" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
2006-12-21 13:35:32 +00:00
|
|
|
}
|
2011-01-19 17:16:29 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2010-12-09 18:34:28 +00:00
|
|
|
// Main method
|
2011-01-19 16:06:33 +00:00
|
|
|
ajax: function( url , options ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Handle varargs
|
2010-12-09 18:34:28 +00:00
|
|
|
if ( arguments.length === 1 ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
options = url;
|
|
|
|
url = options ? options.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
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Get the url if provided separately
|
|
|
|
options.url = url || options.url;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-19 16:06:33 +00:00
|
|
|
var // Create the final options object
|
|
|
|
s = jQuery.extend( true , {} , jQuery.ajaxSettings , options ),
|
|
|
|
// jQuery lists
|
2010-12-25 17:54:37 +00:00
|
|
|
jQuery_lastModified = jQuery.lastModified,
|
|
|
|
jQuery_etag = jQuery.etag,
|
|
|
|
// Callbacks contexts
|
2011-01-19 16:06:33 +00:00
|
|
|
callbackContext = options.context || s.context || s,
|
|
|
|
globalEventContext = callbackContext === s ? jQuery.event : jQuery( callbackContext ),
|
2010-12-25 17:54:37 +00:00
|
|
|
// Deferreds
|
|
|
|
deferred = jQuery.Deferred(),
|
|
|
|
completeDeferred = jQuery._Deferred(),
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
|
|
|
statusCode = s.statusCode || {},
|
2010-12-25 17:54:37 +00:00
|
|
|
// Headers (they are sent all at once)
|
|
|
|
requestHeaders = {},
|
|
|
|
// Response headers
|
|
|
|
responseHeadersString,
|
|
|
|
responseHeaders,
|
|
|
|
// transport
|
|
|
|
transport,
|
|
|
|
// timeout handle
|
|
|
|
timeoutTimer,
|
2011-01-12 23:41:10 +00:00
|
|
|
// Cross-domain detection vars
|
|
|
|
loc = document.location,
|
2011-01-19 17:35:40 +00:00
|
|
|
protocol = loc.protocol || "http:",
|
2011-01-12 23:41:10 +00:00
|
|
|
parts,
|
2010-12-25 17:54:37 +00:00
|
|
|
// The jXHR state
|
|
|
|
state = 0,
|
|
|
|
// Loop variable
|
|
|
|
i,
|
|
|
|
// Fake xhr
|
|
|
|
jXHR = {
|
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
|
|
|
|
setRequestHeader: function(name,value) {
|
|
|
|
if ( state === 0 ) {
|
|
|
|
requestHeaders[ name.toLowerCase() ] = value;
|
|
|
|
}
|
|
|
|
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-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( state === 2 ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-19 16:21:51 +00:00
|
|
|
if ( !responseHeaders ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
responseHeaders = {};
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-19 16:21:51 +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
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
|
2011-01-19 16:21:51 +00:00
|
|
|
return match || null;
|
2010-12-25 17:54:37 +00:00
|
|
|
},
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Cancel the request
|
|
|
|
abort: function( statusText ) {
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( transport ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
transport.abort( statusText || "abort" );
|
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
done( 0 , statusText );
|
2010-12-25 17:54:37 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-01-19 16:06:33 +00:00
|
|
|
// We force the original context
|
|
|
|
// (plain objects used as context get extended)
|
|
|
|
s.context = options.context;
|
|
|
|
|
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)
|
|
|
|
function done( status , statusText , response , 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-16 01:57:39 +00:00
|
|
|
// Dereference transport for early garbage collection
|
|
|
|
// (no matter how long the jXHR transport 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
|
|
|
// Set readyState
|
|
|
|
jXHR.readyState = status ? 4 : 0;
|
|
|
|
|
|
|
|
// Cache response headers
|
|
|
|
responseHeadersString = headers || "";
|
|
|
|
|
|
|
|
// Clear timeout if it exists
|
|
|
|
if ( timeoutTimer ) {
|
|
|
|
clearTimeout(timeoutTimer);
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
var // Reference url
|
|
|
|
url = s.url,
|
|
|
|
// and ifModified status
|
|
|
|
ifModified = s.ifModified,
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Is it a success?
|
|
|
|
isSuccess = 0,
|
|
|
|
// Stored success
|
|
|
|
success,
|
|
|
|
// Stored error
|
2011-01-19 16:51:33 +00:00
|
|
|
error,
|
|
|
|
|
|
|
|
// Keep track of statusCode callbacks
|
|
|
|
oldStatusCode = statusCode;
|
|
|
|
|
|
|
|
statusCode = undefined;
|
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
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
var lastModified = jXHR.getResponseHeader("Last-Modified"),
|
|
|
|
etag = jXHR.getResponseHeader("Etag");
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if (lastModified) {
|
|
|
|
jQuery_lastModified[ s.url ] = lastModified;
|
|
|
|
}
|
|
|
|
if (etag) {
|
|
|
|
jQuery_etag[ s.url ] = etag;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
// Set the statusText accordingly
|
|
|
|
statusText = "notmodified";
|
|
|
|
// Mark as a success
|
2010-12-25 17:54:37 +00:00
|
|
|
isSuccess = 1;
|
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
|
|
|
|
|
|
|
// Set the statusText accordingly
|
|
|
|
statusText = "success";
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Chain data conversions and determine the final value
|
|
|
|
// (if an exception is thrown in the process, it'll be notified as an error)
|
|
|
|
try {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
var i,
|
2011-01-13 00:18:46 +00:00
|
|
|
// Current dataType
|
2010-12-25 17:54:37 +00:00
|
|
|
current,
|
2011-01-13 00:18:46 +00:00
|
|
|
// Previous dataType
|
2010-12-25 17:54:37 +00:00
|
|
|
prev,
|
2011-01-19 16:51:33 +00:00
|
|
|
// Conversion expression
|
|
|
|
conversion,
|
2011-01-13 00:18:46 +00:00
|
|
|
// Conversion function
|
2010-12-29 17:44:45 +00:00
|
|
|
conv,
|
2011-01-13 00:18:46 +00:00
|
|
|
// Conversion functions (when text is used in-between)
|
2010-12-25 17:54:37 +00:00
|
|
|
conv1,
|
|
|
|
conv2,
|
2011-01-13 00:18:46 +00:00
|
|
|
// Local references to dataTypes & converters
|
2010-12-25 17:54:37 +00:00
|
|
|
dataTypes = s.dataTypes,
|
2010-12-28 01:30:51 +00:00
|
|
|
converters = s.converters,
|
2011-01-13 00:18:46 +00:00
|
|
|
// DataType to responseXXX field mapping
|
2010-12-25 17:54:37 +00:00
|
|
|
responses = {
|
|
|
|
"xml": "XML",
|
|
|
|
"text": "Text"
|
|
|
|
};
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// For each dataType in the chain
|
2010-12-25 17:54:37 +00:00
|
|
|
for( i = 0 ; i < dataTypes.length ; i++ ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
current = dataTypes[ i ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// If a responseXXX field for this dataType exists
|
|
|
|
// and if it hasn't been set yet
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( responses[ current ] ) {
|
2011-01-13 00:18:46 +00:00
|
|
|
// Set it
|
2010-12-25 17:54:37 +00:00
|
|
|
jXHR[ "response" + responses[ current ] ] = response;
|
2011-01-13 00:18:46 +00:00
|
|
|
// Mark it as set
|
2010-12-25 17:54:37 +00:00
|
|
|
responses[ current ] = 0;
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// If this is not the first element
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( i ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// Get the dataType to convert from
|
2010-12-25 22:00:25 +00:00
|
|
|
prev = dataTypes[ i - 1 ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// If no catch-all and dataTypes are actually different
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( prev !== "*" && current !== "*" && prev !== current ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// Get the converter
|
2011-01-19 16:51:33 +00:00
|
|
|
conversion = prev + " " + current;
|
|
|
|
conv = converters[ conversion ] || converters[ "* " + current ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-29 17:44:45 +00:00
|
|
|
conv1 = conv2 = 0;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:18:46 +00:00
|
|
|
// If there is no direct converter and none of the dataTypes is text
|
2010-12-29 17:44:45 +00:00
|
|
|
if ( ! conv && prev !== "text" && current !== "text" ) {
|
2011-01-13 00:18:46 +00:00
|
|
|
// Try with text in-between
|
2010-12-29 17:44:45 +00:00
|
|
|
conv1 = converters[ prev + " text" ] || converters[ "* text" ];
|
|
|
|
conv2 = converters[ "text " + current ];
|
2011-01-13 00:18:46 +00:00
|
|
|
// Revert back to a single converter
|
|
|
|
// if one of the converter is an equivalence
|
2010-12-29 17:44:45 +00:00
|
|
|
if ( conv1 === true ) {
|
|
|
|
conv = conv2;
|
|
|
|
} else if ( conv2 === true ) {
|
|
|
|
conv = conv1;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-13 00:18:46 +00:00
|
|
|
// If we found no converter, dispatch an error
|
2010-12-29 17:44:45 +00:00
|
|
|
if ( ! ( conv || conv1 && conv2 ) ) {
|
|
|
|
throw conversion;
|
|
|
|
}
|
2011-01-13 00:18:46 +00:00
|
|
|
// If found converter is not an equivalence
|
2010-12-29 17:44:45 +00:00
|
|
|
if ( conv !== true ) {
|
2011-01-13 00:18:46 +00:00
|
|
|
// Convert with 1 or 2 converters accordingly
|
2010-12-29 17:44:45 +00:00
|
|
|
response = conv ? conv( response ) : conv2( conv1( response ) );
|
|
|
|
}
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-13 00:18:46 +00:00
|
|
|
// If it is the first element of the chain
|
|
|
|
// and we have a dataFilter
|
2010-12-25 17:54:37 +00:00
|
|
|
} else if ( s.dataFilter ) {
|
2011-01-13 00:18:46 +00:00
|
|
|
// Apply the dataFilter
|
2011-01-12 23:49:58 +00:00
|
|
|
response = s.dataFilter( response , current );
|
2011-01-13 00:18:46 +00:00
|
|
|
// Get dataTypes again in case the filter changed them
|
2010-12-25 17:54:37 +00:00
|
|
|
dataTypes = s.dataTypes;
|
|
|
|
}
|
|
|
|
}
|
2011-01-13 00:18:46 +00:00
|
|
|
// End of loop
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// We have a real success
|
|
|
|
success = response;
|
|
|
|
isSuccess = 1;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
// If an exception was thrown
|
2010-12-25 17:54:37 +00:00
|
|
|
} catch(e) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
// We have a parsererror
|
2010-12-25 17:54:37 +00:00
|
|
|
statusText = "parsererror";
|
|
|
|
error = "" + e;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
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 success, mark it as an error
|
|
|
|
} else {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 00:43:42 +00:00
|
|
|
error = statusText = statusText || "error";
|
2011-01-09 03:53:29 +00:00
|
|
|
|
|
|
|
// Set responseText if needed
|
|
|
|
if ( response ) {
|
|
|
|
jXHR.responseText = response;
|
|
|
|
}
|
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
|
|
|
|
jXHR.status = status;
|
|
|
|
jXHR.statusText = statusText;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Success/Error
|
|
|
|
if ( isSuccess ) {
|
|
|
|
deferred.fire( callbackContext , [ success , statusText , jXHR ] );
|
|
|
|
} else {
|
|
|
|
deferred.fireReject( callbackContext , [ jXHR , statusText , error ] );
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
2011-01-19 16:51:33 +00:00
|
|
|
jXHR.statusCode( oldStatusCode );
|
2011-01-13 16:01:25 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( s.global ) {
|
|
|
|
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ) ,
|
|
|
|
[ jXHR , s , isSuccess ? success : error ] );
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Complete
|
|
|
|
completeDeferred.fire( callbackContext, [ jXHR , statusText ] );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( s.global ) {
|
|
|
|
globalEventContext.trigger( "ajaxComplete" , [ jXHR , s] );
|
|
|
|
// Handle the global AJAX counter
|
|
|
|
if ( ! --jQuery.active ) {
|
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-28 03:13:44 +00:00
|
|
|
// Attach deferreds
|
|
|
|
deferred.promise( jXHR );
|
2011-01-06 00:26:06 +00:00
|
|
|
jXHR.success = jXHR.done;
|
2010-12-28 03:13:44 +00:00
|
|
|
jXHR.error = jXHR.fail;
|
2011-01-06 00:26:06 +00:00
|
|
|
jXHR.complete = completeDeferred.done;
|
2010-12-25 17:54:37 +00:00
|
|
|
|
2011-01-13 16:01:25 +00:00
|
|
|
// Status-dependent callbacks
|
|
|
|
jXHR.statusCode = function( map ) {
|
|
|
|
if ( map ) {
|
2011-01-19 16:51:33 +00:00
|
|
|
var tmp;
|
|
|
|
if ( statusCode ) {
|
2011-01-13 16:01:25 +00:00
|
|
|
for( tmp in map ) {
|
|
|
|
statusCode[ tmp ] = [ statusCode[ tmp ] , map[ tmp ] ];
|
|
|
|
}
|
2011-01-19 16:51:33 +00:00
|
|
|
} else {
|
|
|
|
tmp = map[ jXHR.status ];
|
|
|
|
jXHR.done( tmp ).fail( 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)
|
|
|
|
s.url = ( "" + s.url ).replace( rhash , "" );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Extract dataTypes list
|
|
|
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( /\s+/ );
|
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-01-09 15:50:13 +00:00
|
|
|
if ( ! s.crossDomain ) {
|
2011-01-12 23:41:10 +00:00
|
|
|
parts = rurl.exec( s.url.toLowerCase() );
|
2011-01-09 15:50:13 +00:00
|
|
|
s.crossDomain = !!(
|
|
|
|
parts &&
|
2011-01-19 17:35:40 +00:00
|
|
|
( parts[ 1 ] && parts[ 1 ] != protocol ||
|
2011-01-09 15:50:13 +00:00
|
|
|
parts[ 2 ] != loc.hostname ||
|
2011-01-19 17:35:40 +00:00
|
|
|
( parts[ 3 ] || ( ( parts[ 1 ] || protocol ) === "http:" ? 80 : 443 ) )
|
|
|
|
!= ( loc.port || ( protocol === "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" ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
s.data = jQuery.param( s.data , s.traditional );
|
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Apply prefilters
|
|
|
|
jQuery.ajaxPrefilter( s , options );
|
2011-01-09 15:32:51 +00:00
|
|
|
|
2011-01-16 04:24:14 +00:00
|
|
|
// Uppercase the type
|
|
|
|
s.type = s.type.toUpperCase();
|
|
|
|
|
|
|
|
// Determine if request has content
|
|
|
|
s.hasContent = ! rnoContent.test( s.type );
|
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Watch for a new set of requests
|
|
|
|
if ( s.global && jQuery.active++ === 0 ) {
|
|
|
|
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
|
|
|
|
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-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 ) {
|
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
|
|
|
|
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
|
|
|
|
s.url = ret + ( (ret == s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "");
|
|
|
|
}
|
|
|
|
}
|
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 ) {
|
|
|
|
requestHeaders[ "content-type" ] = s.contentType;
|
|
|
|
}
|
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 ) {
|
|
|
|
if ( jQuery_lastModified[ s.url ] ) {
|
|
|
|
requestHeaders[ "if-modified-since" ] = jQuery_lastModified[ s.url ];
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-16 01:57:39 +00:00
|
|
|
if ( jQuery_etag[ s.url ] ) {
|
|
|
|
requestHeaders[ "if-none-match" ] = jQuery_etag[ s.url ];
|
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
|
|
|
|
requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
|
|
|
s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
|
|
|
s.accepts[ "*" ];
|
|
|
|
|
|
|
|
// Check for headers option
|
|
|
|
for ( i in s.headers ) {
|
|
|
|
requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Allow custom headers/mimetypes and early abort
|
|
|
|
if ( s.beforeSend && ( s.beforeSend.call( callbackContext , jXHR , s ) === false || state === 2 ) ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Abort if not done already
|
|
|
|
done( 0 , "abort" );
|
|
|
|
|
|
|
|
// Return false
|
|
|
|
jXHR = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Install callbacks on deferreds
|
|
|
|
for ( i in { success:1, error:1, complete:1 } ) {
|
|
|
|
jXHR[ i ]( s[ i ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// Get transport
|
2011-01-19 17:16:29 +00:00
|
|
|
transport = jQuery.ajaxTransport( s , options );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-16 01:57:39 +00:00
|
|
|
// If no transport, we auto-abort
|
|
|
|
if ( ! transport ) {
|
|
|
|
|
|
|
|
done( 0 , "notransport" );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
} else {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Set state as sending
|
2011-01-16 01:57:39 +00:00
|
|
|
state = jXHR.readyState = 1;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Send global event
|
|
|
|
if ( s.global ) {
|
|
|
|
globalEventContext.trigger( "ajaxSend" , [ jXHR , s ] );
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Timeout
|
|
|
|
if ( s.async && s.timeout > 0 ) {
|
|
|
|
timeoutTimer = setTimeout(function(){
|
|
|
|
jXHR.abort( "timeout" );
|
|
|
|
}, s.timeout);
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Try to send
|
|
|
|
try {
|
|
|
|
transport.send(requestHeaders, done);
|
|
|
|
} catch (e) {
|
|
|
|
// Propagate exception as error if not done
|
|
|
|
if ( status === 1 ) {
|
|
|
|
|
|
|
|
done(0, "error", "" + e);
|
|
|
|
jXHR = false;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
// Simply rethrow otherwise
|
|
|
|
} else {
|
|
|
|
jQuery.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
return jXHR;
|
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
|
|
|
|
value = jQuery.isFunction(value) ? value() : value;
|
|
|
|
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
|
|
|
};
|
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.
|
|
|
|
if ( jQuery.isArray(a) || a.jquery ) {
|
|
|
|
// Serialize the form elements
|
|
|
|
jQuery.each( a, function() {
|
|
|
|
add( this.name, this.value );
|
|
|
|
});
|
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 ) {
|
|
|
|
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
|
|
|
|
return s.join("&").replace(r20, "+");
|
|
|
|
}
|
|
|
|
});
|
2007-09-03 23:45:14 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
function buildParams( prefix, obj, traditional, add ) {
|
2010-09-24 20:57:25 +00:00
|
|
|
if ( jQuery.isArray(obj) && obj.length ) {
|
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" ) {
|
2010-12-23 00:54:22 +00:00
|
|
|
// If we see an array here, it is empty and should be treated as an empty
|
|
|
|
// object
|
|
|
|
if ( jQuery.isArray( obj ) || jQuery.isEmptyObject( obj ) ) {
|
2010-09-24 20:57:25 +00:00
|
|
|
add( prefix, "" );
|
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
// Serialize object item.
|
2010-09-24 20:57:25 +00:00
|
|
|
} else {
|
|
|
|
jQuery.each( obj, function( k, v ) {
|
|
|
|
buildParams( prefix + "[" + k + "]", v, traditional, add );
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
//Execute or select from functions in a given structure of options
|
2011-01-19 17:16:29 +00:00
|
|
|
function ajax_selectOrExecute( structure , s , options ) {
|
2010-12-25 17:54:37 +00:00
|
|
|
|
|
|
|
var dataTypes = s.dataTypes,
|
|
|
|
transportDataType,
|
|
|
|
list,
|
|
|
|
selected,
|
|
|
|
i,
|
|
|
|
length,
|
|
|
|
checked = {},
|
|
|
|
flag,
|
|
|
|
noSelect = structure !== "transports";
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
function initSearch( dataType ) {
|
|
|
|
|
|
|
|
flag = transportDataType !== dataType && ! checked[ dataType ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( flag ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
checked[ dataType ] = 1;
|
|
|
|
transportDataType = dataType;
|
|
|
|
list = s[ structure ][ dataType ];
|
|
|
|
i = -1;
|
|
|
|
length = list ? list.length : 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
initSearch( dataTypes[ 0 ] );
|
|
|
|
|
|
|
|
for ( i = 0 ; ( noSelect || ! selected ) && i <= length ; i++ ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( i === length ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
initSearch( "*" );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
} else {
|
|
|
|
|
2011-01-19 17:16:29 +00:00
|
|
|
selected = list[ i ]( s , options );
|
2010-12-25 17:54:37 +00:00
|
|
|
|
|
|
|
// If we got redirected to another dataType
|
|
|
|
// Search there (if not in progress or already tried)
|
|
|
|
if ( typeof( selected ) === "string" &&
|
|
|
|
initSearch( selected ) ) {
|
|
|
|
|
|
|
|
dataTypes.unshift( selected );
|
|
|
|
selected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 17:33:24 +00:00
|
|
|
return noSelect ? jQuery : selected;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add an element to one of the structures in ajaxSettings
|
|
|
|
function ajax_addElement( structure , args ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
var i,
|
|
|
|
start = 0,
|
|
|
|
length = args.length,
|
|
|
|
dataTypes = [ "*" ],
|
|
|
|
dLength = 1,
|
|
|
|
dataType,
|
|
|
|
functors = [],
|
|
|
|
first,
|
|
|
|
append,
|
|
|
|
list;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( length ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
first = jQuery.type( args[ 0 ] );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( first === "object" ) {
|
2011-01-19 17:16:29 +00:00
|
|
|
return ajax_selectOrExecute( structure , args[ 0 ] , args[ 1 ] );
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
structure = jQuery.ajaxSettings[ structure ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( first !== "function" ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
dataTypes = args[ 0 ].toLowerCase().split(/\s+/);
|
|
|
|
dLength = dataTypes.length;
|
|
|
|
start = 1;
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( dLength && start < length ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
functors = sliceFunc.call( args , start );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
for( i = 0 ; i < dLength ; i++ ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
dataType = dataTypes[ i ];
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
first = /^\+/.test( dataType );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if (first) {
|
|
|
|
dataType = dataType.substr(1);
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
if ( dataType !== "" ) {
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-25 17:54:37 +00:00
|
|
|
append = Array.prototype[ first ? "unshift" : "push" ];
|
|
|
|
list = structure[ dataType ] = structure[ dataType ] || [];
|
|
|
|
append.apply( list , functors );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2011-01-13 17:33:24 +00:00
|
|
|
return jQuery;
|
2010-12-25 17:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Install prefilter & transport methods
|
2011-01-13 17:33:24 +00:00
|
|
|
jQuery.each( [ "Prefilter" , "Transport" ] , function( _ , name ) {
|
|
|
|
_ = name.toLowerCase() + "s";
|
|
|
|
jQuery[ "ajax" + name ] = function() {
|
2010-12-25 17:54:37 +00:00
|
|
|
return ajax_addElement( _ , arguments );
|
|
|
|
};
|
|
|
|
} );
|
2011-01-05 21:41:23 +00:00
|
|
|
|
2010-12-10 02:16:50 +00:00
|
|
|
})( jQuery );
|