2010-09-08 17:54:33 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2010-03-23 16:12:16 +00:00
|
|
|
var jsc = jQuery.now(),
|
2009-12-17 02:13:50 +00:00
|
|
|
rscript = /<script(.|\s)*?\/script>/gi,
|
2009-07-19 19:44:15 +00:00
|
|
|
rselectTextarea = /select|textarea/i,
|
2009-12-17 02:02:58 +00:00
|
|
|
rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,
|
2010-03-01 23:19:29 +00:00
|
|
|
jsre = /\=\?(&|$)/,
|
2009-07-19 19:44:15 +00:00
|
|
|
rquery = /\?/,
|
|
|
|
rts = /(\?|&)_=.*?(&|$)/,
|
|
|
|
rurl = /^(\w+:)?\/\/([^\/?#]+)/,
|
2010-02-11 06:23:13 +00:00
|
|
|
r20 = /%20/g,
|
2009-07-19 19:44:15 +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
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2010-01-25 02:58:32 +00:00
|
|
|
var self = this;
|
|
|
|
|
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,
|
2009-12-22 00:58:13 +00:00
|
|
|
complete: function( res, status ) {
|
2007-07-20 21:59:52 +00:00
|
|
|
// If successful, inject the HTML into all the matched elements
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( status === "success" || status === "notmodified" ) {
|
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
|
2009-09-15 15:19:58 +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
|
2009-07-19 19:44:15 +00:00
|
|
|
.append(res.responseText.replace(rscript, ""))
|
2007-08-25 03:33:08 +00:00
|
|
|
|
|
|
|
// Locate the specified elements
|
|
|
|
.find(selector) :
|
|
|
|
|
|
|
|
// If not, just inject the full result
|
|
|
|
res.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 ) {
|
2010-01-25 02:58:32 +00:00
|
|
|
self.each( callback, [res.responseText, status, res] );
|
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() {
|
2009-12-22 00:58:13 +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
|
|
|
})
|
2009-12-22 00:58:13 +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
|
|
|
})
|
2009-12-22 00:58:13 +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) ?
|
2009-12-22 00:58:13 +00:00
|
|
|
jQuery.map( val, function( val, i ) {
|
|
|
|
return { name: elem.name, value: val };
|
2007-09-05 17:06:05 +00:00
|
|
|
}) :
|
2009-12-22 00:58:13 +00:00
|
|
|
{ name: elem.name, value: val };
|
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
|
2009-12-22 00:58:13 +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
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
jQuery.extend({
|
2007-09-04 02:55:38 +00:00
|
|
|
get: 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({
|
2007-03-17 14:18:06 +00:00
|
|
|
type: "GET",
|
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
|
|
|
});
|
2006-08-17 04:18:32 +00:00
|
|
|
},
|
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
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
post: function( url, data, callback, type ) {
|
2009-09-15 15:28:28 +00:00
|
|
|
// shift arguments if data argument was omited
|
2007-01-22 03:49:04 +00:00
|
|
|
if ( jQuery.isFunction( data ) ) {
|
2009-09-15 16:45:37 +00:00
|
|
|
type = type || callback;
|
2007-01-22 03:49:04 +00:00
|
|
|
callback = data;
|
|
|
|
data = {};
|
|
|
|
}
|
|
|
|
|
2006-12-15 09:13:24 +00:00
|
|
|
return jQuery.ajax({
|
2006-11-03 11:30:57 +00:00
|
|
|
type: "POST",
|
|
|
|
url: url,
|
2006-11-11 11:34:51 +00:00
|
|
|
data: data,
|
|
|
|
success: callback,
|
|
|
|
dataType: type
|
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 ) {
|
2007-08-21 04:46:07 +00:00
|
|
|
jQuery.extend( jQuery.ajaxSettings, settings );
|
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,
|
|
|
|
username: null,
|
2008-01-14 18:19:28 +00:00
|
|
|
password: null,
|
2009-12-22 13:09:56 +00:00
|
|
|
traditional: false,
|
2009-01-04 21:15:02 +00:00
|
|
|
*/
|
2008-08-07 13:07:21 +00:00
|
|
|
// Create the request object; Microsoft failed to properly
|
2010-01-05 15:57:30 +00:00
|
|
|
// implement the XMLHttpRequest in IE7 (can't request local files),
|
|
|
|
// so we use the ActiveXObject when it is available
|
2008-08-07 13:07:21 +00:00
|
|
|
// This function can be overriden by calling jQuery.ajaxSetup
|
2010-01-07 15:00:55 +00:00
|
|
|
xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ?
|
|
|
|
function() {
|
2010-01-05 16:35:11 +00:00
|
|
|
return new window.XMLHttpRequest();
|
2010-01-07 15:00:55 +00:00
|
|
|
} :
|
|
|
|
function() {
|
2010-01-05 16:35:11 +00:00
|
|
|
try {
|
|
|
|
return new window.ActiveXObject("Microsoft.XMLHTTP");
|
|
|
|
} catch(e) {}
|
2010-01-07 15:00:55 +00:00
|
|
|
},
|
2008-01-14 18:19:28 +00:00
|
|
|
accepts: {
|
|
|
|
xml: "application/xml, text/xml",
|
|
|
|
html: "text/html",
|
|
|
|
script: "text/javascript, application/javascript",
|
|
|
|
json: "application/json, text/javascript",
|
|
|
|
text: "text/plain",
|
2008-01-14 19:37:05 +00:00
|
|
|
_default: "*/*"
|
2008-01-14 18:19:28 +00:00
|
|
|
}
|
2006-12-22 13:56:36 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-12-05 02:20:58 +00:00
|
|
|
ajax: function( origSettings ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
|
|
|
|
jsonp, status, data, type = s.type.toUpperCase();
|
|
|
|
|
|
|
|
s.context = origSettings && origSettings.context || s;
|
2008-05-15 14:16:19 +00:00
|
|
|
|
2007-09-03 23:45:14 +00:00
|
|
|
// convert data if not already a string
|
2009-07-19 19:03:18 +00:00
|
|
|
if ( s.data && s.processData && typeof s.data !== "string" ) {
|
2009-12-22 13:09:56 +00:00
|
|
|
s.data = jQuery.param( s.data, s.traditional );
|
2009-07-19 19:03:18 +00:00
|
|
|
}
|
2007-08-19 23:37:26 +00:00
|
|
|
|
2007-09-03 23:45:14 +00:00
|
|
|
// Handle JSONP Parameter Callbacks
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.dataType === "jsonp" ) {
|
|
|
|
if ( type === "GET" ) {
|
2009-07-19 19:03:18 +00:00
|
|
|
if ( !jsre.test( s.url ) ) {
|
2009-07-19 19:44:15 +00:00
|
|
|
s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
|
2009-07-19 19:03:18 +00:00
|
|
|
}
|
|
|
|
} else if ( !s.data || !jsre.test(s.data) ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
|
2009-07-19 19:03:18 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
s.dataType = "json";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build temporary JSONP function
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
|
2009-12-07 01:17:14 +00:00
|
|
|
jsonp = s.jsonpCallback || ("jsonp" + jsc++);
|
2007-09-15 01:18:30 +00:00
|
|
|
|
|
|
|
// Replace the =? sequence both in the query string and the data
|
2009-07-19 19:03:18 +00:00
|
|
|
if ( s.data ) {
|
2007-12-17 00:48:12 +00:00
|
|
|
s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
|
2009-07-19 19:03:18 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 00:48:12 +00:00
|
|
|
s.url = s.url.replace(jsre, "=" + jsonp + "$1");
|
2007-09-03 23:45:14 +00:00
|
|
|
|
|
|
|
// We need to make sure
|
|
|
|
// that a JSONP style response is executed properly
|
|
|
|
s.dataType = "script";
|
|
|
|
|
|
|
|
// Handle JSONP-style loading
|
2010-04-29 03:45:34 +00:00
|
|
|
var customJsonp = window[ jsonp ];
|
2010-06-15 03:05:01 +00:00
|
|
|
|
2010-04-29 03:45:34 +00:00
|
|
|
window[ jsonp ] = function( tmp ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
data = tmp;
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleSuccess( s, xhr, status, data );
|
|
|
|
jQuery.ajax.handleComplete( s, xhr, status, data );
|
2010-04-29 03:45:34 +00:00
|
|
|
|
|
|
|
if ( jQuery.isFunction( customJsonp ) ) {
|
2010-06-15 03:05:01 +00:00
|
|
|
customJsonp( tmp );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Garbage collect
|
|
|
|
window[ jsonp ] = undefined;
|
|
|
|
|
|
|
|
try {
|
|
|
|
delete window[ jsonp ];
|
|
|
|
} catch( jsonpError ) {}
|
|
|
|
}
|
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( head ) {
|
2007-12-17 00:51:59 +00:00
|
|
|
head.removeChild( script );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.dataType === "script" && s.cache === null ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
s.cache = false;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.cache === false && type === "GET" ) {
|
2010-03-23 16:12:16 +00:00
|
|
|
var ts = jQuery.now();
|
2009-07-19 19:37:11 +00:00
|
|
|
|
2007-12-04 04:43:45 +00:00
|
|
|
// try replacing _= if it is there
|
2009-07-19 19:44:15 +00:00
|
|
|
var ret = s.url.replace(rts, "$1_=" + ts + "$2");
|
2009-07-19 19:37:11 +00:00
|
|
|
|
2007-12-04 04:43:45 +00:00
|
|
|
// if nothing was replaced, add timestamp to the end
|
2009-07-19 19:44:15 +00:00
|
|
|
s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : "");
|
2007-12-04 04:43:45 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
|
|
|
|
// If data is available, append data to url for get requests
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.data && type === "GET" ) {
|
2009-07-19 19:44:15 +00:00
|
|
|
s.url += (rquery.test(s.url) ? "&" : "?") + s.data;
|
2006-07-10 03:20:56 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
// Watch for a new set of requests
|
2010-03-02 02:24:49 +00:00
|
|
|
if ( s.global && jQuery.ajax.active++ === 0 ) {
|
2006-07-10 03:20:56 +00:00
|
|
|
jQuery.event.trigger( "ajaxStart" );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-08-22 07:32:25 +00:00
|
|
|
|
2008-05-13 19:58:00 +00:00
|
|
|
// Matches an absolute URL, and saves the domain
|
2009-11-25 18:29:34 +00:00
|
|
|
var parts = rurl.exec( s.url ),
|
|
|
|
remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
|
2008-05-13 19:58:00 +00:00
|
|
|
|
2007-09-03 23:45:14 +00:00
|
|
|
// If we're requesting a remote document
|
2007-12-11 20:16:19 +00:00
|
|
|
// and trying to load JSON or Script with a GET
|
2009-11-25 18:29:34 +00:00
|
|
|
if ( s.dataType === "script" && type === "GET" && remote ) {
|
2009-09-14 20:55:40 +00:00
|
|
|
var head = document.getElementsByTagName("head")[0] || document.documentElement;
|
2007-09-03 23:45:14 +00:00
|
|
|
var script = document.createElement("script");
|
|
|
|
script.src = s.url;
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.scriptCharset ) {
|
2007-12-15 23:30:34 +00:00
|
|
|
script.charset = s.scriptCharset;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
|
|
|
|
// Handle Script loading
|
2007-10-17 23:13:31 +00:00
|
|
|
if ( !jsonp ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
var done = false;
|
|
|
|
|
|
|
|
// Attach handlers for all browsers
|
2009-12-22 00:58:13 +00:00
|
|
|
script.onload = script.onreadystatechange = function() {
|
2008-05-13 01:45:58 +00:00
|
|
|
if ( !done && (!this.readyState ||
|
2009-07-19 19:37:11 +00:00
|
|
|
this.readyState === "loaded" || this.readyState === "complete") ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
done = true;
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleSuccess( s, xhr, status, data );
|
|
|
|
jQuery.ajax.handleComplete( s, xhr, status, data );
|
2009-02-07 16:57:59 +00:00
|
|
|
|
|
|
|
// Handle memory leak in IE
|
|
|
|
script.onload = script.onreadystatechange = null;
|
2009-07-22 14:38:21 +00:00
|
|
|
if ( head && script.parentNode ) {
|
|
|
|
head.removeChild( script );
|
|
|
|
}
|
2007-09-03 23:45:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-03-27 18:20:57 +00:00
|
|
|
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
|
|
|
|
// This arises when a base node is used (#2709 and #4378).
|
|
|
|
head.insertBefore( script, head.firstChild );
|
2007-09-03 23:45:14 +00:00
|
|
|
|
|
|
|
// We handle everything using the script element injection
|
2007-12-16 01:03:50 +00:00
|
|
|
return undefined;
|
2007-09-03 23:45:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-22 07:32:25 +00:00
|
|
|
var requestDone = false;
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2008-08-04 14:18:06 +00:00
|
|
|
// Create the request object
|
2008-08-07 13:07:21 +00:00
|
|
|
var xhr = s.xhr();
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2010-01-05 16:35:11 +00:00
|
|
|
if ( !xhr ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
// Open the socket
|
2008-05-15 13:45:09 +00:00
|
|
|
// Passing null username, generates a login popup on Opera (#2865)
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.username ) {
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr.open(type, s.url, s.async, s.username, s.password);
|
2009-07-19 19:37:11 +00:00
|
|
|
} else {
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr.open(type, s.url, s.async);
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2007-12-14 02:04:00 +00:00
|
|
|
// Need an extra try/catch for cross domain requests in Firefox 3
|
|
|
|
try {
|
|
|
|
// Set the correct header, if data is being sent
|
2009-12-05 23:06:27 +00:00
|
|
|
if ( s.data || origSettings && origSettings.contentType ) {
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr.setRequestHeader("Content-Type", s.contentType);
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2009-11-25 18:24:24 +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] ) {
|
|
|
|
xhr.setRequestHeader("If-Modified-Since", jQuery.lastModified[s.url]);
|
|
|
|
}
|
2009-07-19 19:37:11 +00:00
|
|
|
|
2010-03-02 15:44:48 +00:00
|
|
|
if ( jQuery.ajax.etag[s.url] ) {
|
|
|
|
xhr.setRequestHeader("If-None-Match", jQuery.ajax.etag[s.url]);
|
2009-06-15 13:36:12 +00:00
|
|
|
}
|
2009-11-25 18:24:24 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2007-12-14 02:04:00 +00:00
|
|
|
// Set header so the called script knows that it's an XMLHttpRequest
|
2009-11-25 18:29:34 +00:00
|
|
|
// Only send the header if it's not a remote XHR
|
|
|
|
if ( !remote ) {
|
|
|
|
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
|
|
}
|
2008-01-14 18:19:28 +00:00
|
|
|
|
|
|
|
// Set the Accepts header for the server, depending on the dataType
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
|
2008-01-14 18:19:28 +00:00
|
|
|
s.accepts[ s.dataType ] + ", */*" :
|
2008-01-14 19:37:31 +00:00
|
|
|
s.accepts._default );
|
2010-03-02 02:24:49 +00:00
|
|
|
} catch( headerError ) {}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2008-11-14 04:16:00 +00:00
|
|
|
// Allow custom headers/mimetypes and early abort
|
2010-03-02 02:24:49 +00:00
|
|
|
if ( s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false ) {
|
2008-11-14 04:16:00 +00:00
|
|
|
// Handle the global AJAX counter
|
2010-03-02 02:24:49 +00:00
|
|
|
if ( s.global && jQuery.ajax.active-- === 1 ) {
|
2008-11-14 04:16:00 +00:00
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2008-04-22 22:18:11 +00:00
|
|
|
// close opended socket
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr.abort();
|
2008-04-22 22:07:17 +00:00
|
|
|
return false;
|
2008-04-22 22:18:11 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.global ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.triggerGlobal( s, "ajaxSend", [xhr, s] );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
// Wait for a response to come back
|
2009-12-31 04:53:06 +00:00
|
|
|
var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
|
2010-01-12 15:59:50 +00:00
|
|
|
// The request was aborted
|
2010-01-25 03:13:52 +00:00
|
|
|
if ( !xhr || xhr.readyState === 0 || isTimeout === "abort" ) {
|
2010-01-12 15:59:50 +00:00
|
|
|
// Opera doesn't call onreadystatechange before this point
|
|
|
|
// so we simulate the call
|
|
|
|
if ( !requestDone ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleComplete( s, xhr, status, data );
|
2010-01-12 15:59:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-31 04:53:06 +00:00
|
|
|
requestDone = true;
|
2010-01-12 15:31:51 +00:00
|
|
|
if ( xhr ) {
|
|
|
|
xhr.onreadystatechange = jQuery.noop;
|
|
|
|
}
|
2009-12-31 04:53:06 +00:00
|
|
|
|
2006-08-17 04:18:32 +00:00
|
|
|
// The transfer is complete and the data is available, or the request timed out
|
2009-07-19 19:37:11 +00:00
|
|
|
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
|
2006-08-22 07:32:25 +00:00
|
|
|
requestDone = true;
|
2009-12-31 14:50:49 +00:00
|
|
|
xhr.onreadystatechange = jQuery.noop;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
status = isTimeout === "timeout" ?
|
|
|
|
"timeout" :
|
2010-03-02 02:24:49 +00:00
|
|
|
!jQuery.ajax.httpSuccess( xhr ) ?
|
2009-07-19 19:37:11 +00:00
|
|
|
"error" :
|
2010-03-02 02:24:49 +00:00
|
|
|
s.ifModified && jQuery.ajax.httpNotModified( xhr, s.url ) ?
|
2009-07-19 19:37:11 +00:00
|
|
|
"notmodified" :
|
|
|
|
"success";
|
2007-08-19 00:48:53 +00:00
|
|
|
|
2010-01-25 23:48:52 +00:00
|
|
|
var errMsg;
|
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( status === "success" ) {
|
2007-08-19 00:48:53 +00:00
|
|
|
// Watch for, and catch, XML document parse errors
|
|
|
|
try {
|
2006-12-21 13:35:32 +00:00
|
|
|
// process the data (runs the xml through httpData regardless of callback)
|
2010-03-02 02:24:49 +00:00
|
|
|
data = jQuery.ajax.httpData( xhr, s.dataType, s );
|
|
|
|
} catch( parserError ) {
|
2007-08-19 00:48:53 +00:00
|
|
|
status = "parsererror";
|
2010-03-02 02:24:49 +00:00
|
|
|
errMsg = parserError;
|
2007-08-19 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that the request was successful or notmodified
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( status === "success" || status === "notmodified" ) {
|
2007-09-03 23:45:14 +00:00
|
|
|
// JSONP handles its own success callback
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( !jsonp ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleSuccess( s, xhr, status, data );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleError( s, xhr, status, errMsg );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2007-09-03 23:45:14 +00:00
|
|
|
// Fire the complete handlers
|
2010-04-29 03:45:34 +00:00
|
|
|
if ( !jsonp ) {
|
2010-06-15 03:05:01 +00:00
|
|
|
jQuery.ajax.handleComplete( s, xhr, status, data );
|
|
|
|
}
|
|
|
|
|
2009-12-09 16:09:41 +00:00
|
|
|
if ( isTimeout === "timeout" ) {
|
2009-01-21 21:46:53 +00:00
|
|
|
xhr.abort();
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2009-01-21 21:46:53 +00:00
|
|
|
|
2006-07-17 04:57:07 +00:00
|
|
|
// Stop memory leaks
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.async ) {
|
2008-05-15 21:03:31 +00:00
|
|
|
xhr = null;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-06-19 01:29:54 +00:00
|
|
|
}
|
2006-07-17 04:57:07 +00:00
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2010-01-12 15:31:51 +00:00
|
|
|
// Override the abort handler, if we can (IE doesn't allow it, but that's OK)
|
|
|
|
// Opera doesn't fire onreadystatechange at all on abort
|
|
|
|
try {
|
|
|
|
var oldAbort = xhr.abort;
|
|
|
|
xhr.abort = function() {
|
2010-01-12 15:47:00 +00:00
|
|
|
if ( xhr ) {
|
2010-01-12 21:50:59 +00:00
|
|
|
oldAbort.call( xhr );
|
2010-01-12 15:47:00 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 03:13:52 +00:00
|
|
|
onreadystatechange( "abort" );
|
2010-01-12 15:31:51 +00:00
|
|
|
};
|
2010-03-02 02:24:49 +00:00
|
|
|
} catch( abortError ) {}
|
2010-01-12 15:31:51 +00:00
|
|
|
|
2009-12-31 04:53:06 +00:00
|
|
|
// Timeout checker
|
|
|
|
if ( s.async && s.timeout > 0 ) {
|
|
|
|
setTimeout(function() {
|
|
|
|
// Check to see if the request is still happening
|
|
|
|
if ( xhr && !requestDone ) {
|
|
|
|
onreadystatechange( "timeout" );
|
|
|
|
}
|
|
|
|
}, s.timeout);
|
2007-08-19 23:37:26 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
// Send the data
|
2006-12-21 13:35:32 +00:00
|
|
|
try {
|
2010-06-15 03:08:28 +00:00
|
|
|
xhr.send( (type !== "GET" && s.data) || null );
|
2010-03-02 02:24:49 +00:00
|
|
|
|
|
|
|
} catch( sendError ) {
|
|
|
|
jQuery.ajax.handleError( s, xhr, null, e );
|
|
|
|
|
2009-11-07 13:59:47 +00:00
|
|
|
// Fire the complete handlers
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.handleComplete( s, xhr, status, data );
|
2006-12-21 13:35:32 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2006-12-29 13:49:28 +00:00
|
|
|
// firefox 1.5 doesn't fire statechange for sync requests
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( !s.async ) {
|
2006-12-29 13:49:28 +00:00
|
|
|
onreadystatechange();
|
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 XMLHttpRequest to allow aborting the request etc.
|
|
|
|
return xhr;
|
|
|
|
},
|
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 ) {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set traditional to true for jQuery <= 1.3.2 behavior.
|
|
|
|
if ( traditional === undefined ) {
|
|
|
|
traditional = jQuery.ajaxSettings.traditional;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
});
|
|
|
|
|
|
|
|
} 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 ) {
|
|
|
|
if ( jQuery.isArray(obj) ) {
|
|
|
|
// Serialize array item.
|
|
|
|
jQuery.each( obj, function( i, v ) {
|
|
|
|
if ( traditional || /\[\]$/.test( prefix ) ) {
|
|
|
|
// 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
|
|
|
});
|
|
|
|
|
|
|
|
} else if ( !traditional && obj != null && typeof obj === "object" ) {
|
|
|
|
// Serialize object item.
|
|
|
|
jQuery.each( obj, function( k, v ) {
|
|
|
|
buildParams( prefix + "[" + k + "]", v, traditional, add );
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Serialize scalar item.
|
|
|
|
add( prefix, obj );
|
|
|
|
}
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.extend( jQuery.ajax, {
|
|
|
|
|
|
|
|
// 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: {},
|
|
|
|
etag: {},
|
|
|
|
|
2008-05-15 21:03:31 +00:00
|
|
|
handleError: function( s, xhr, status, e ) {
|
2006-12-21 13:35:32 +00:00
|
|
|
// If a local callback was specified, fire it
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.error ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
s.error.call( s.context, xhr, status, e );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-12-21 13:35:32 +00:00
|
|
|
|
|
|
|
// Fire the global callback
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( s.global ) {
|
2010-03-02 02:24:49 +00:00
|
|
|
jQuery.ajax.triggerGlobal( s, "ajaxError", [xhr, s, e] );
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2006-12-21 13:35:32 +00:00
|
|
|
},
|
|
|
|
|
2010-03-02 02:24:49 +00:00
|
|
|
handleSuccess: function( s, xhr, status, data ) {
|
|
|
|
// If a local callback was specified, fire it and pass it the data
|
|
|
|
if ( s.success ) {
|
|
|
|
s.success.call( s.context, data, status, xhr );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire the global callback
|
|
|
|
if ( s.global ) {
|
|
|
|
jQuery.ajax.triggerGlobal( s, "ajaxSuccess", [xhr, s] );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleComplete: function( s, xhr, status ) {
|
|
|
|
// Process result
|
|
|
|
if ( s.complete ) {
|
|
|
|
s.complete.call( s.context, xhr, status );
|
|
|
|
}
|
|
|
|
|
|
|
|
// The request was completed
|
|
|
|
if ( s.global ) {
|
|
|
|
jQuery.ajax.triggerGlobal( s, "ajaxComplete", [xhr, s] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the global AJAX counter
|
|
|
|
if ( s.global && jQuery.ajax.active-- === 1 ) {
|
|
|
|
jQuery.event.trigger( "ajaxStop" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
triggerGlobal: function( s, type, args ) {
|
|
|
|
(s.context && s.context.url == null ? jQuery(s.context) : jQuery.event).trigger(type, args);
|
|
|
|
},
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2006-07-10 03:20:56 +00:00
|
|
|
// Determines if an XMLHttpRequest was successful or not
|
2008-05-15 21:03:31 +00:00
|
|
|
httpSuccess: function( xhr ) {
|
2006-12-21 15:23:59 +00:00
|
|
|
try {
|
2007-11-29 17:12:08 +00:00
|
|
|
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
|
2009-07-19 19:37:11 +00:00
|
|
|
return !xhr.status && location.protocol === "file:" ||
|
|
|
|
( xhr.status >= 200 && xhr.status < 300 ) ||
|
2010-09-21 19:22:34 +00:00
|
|
|
xhr.status === 304 || xhr.status === 1223 ||
|
|
|
|
// Opera returns a status of 0 for redirects -
|
|
|
|
// We can detect this by the fact that Opera also doesn't return any headers
|
|
|
|
xhr.status === 0 && !xhr.getAllResponseHeaders();
|
2009-12-22 00:58:13 +00:00
|
|
|
} catch(e) {}
|
2009-07-19 19:37:11 +00:00
|
|
|
|
2006-12-21 15:23:59 +00:00
|
|
|
return false;
|
2006-08-17 04:18:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Determines if an XMLHttpRequest returns NotModified
|
2008-05-15 21:03:31 +00:00
|
|
|
httpNotModified: function( xhr, url ) {
|
2009-09-14 19:57:49 +00:00
|
|
|
var lastModified = xhr.getResponseHeader("Last-Modified"),
|
2009-07-19 19:37:11 +00:00
|
|
|
etag = xhr.getResponseHeader("Etag");
|
2006-08-17 04:18:32 +00:00
|
|
|
|
2009-09-14 19:57:49 +00:00
|
|
|
if ( lastModified ) {
|
2010-03-02 15:44:48 +00:00
|
|
|
jQuery.ajax.lastModified[url] = lastModified;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2009-06-15 13:36:12 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( etag ) {
|
2010-03-02 15:44:48 +00:00
|
|
|
jQuery.ajax.etag[url] = etag;
|
2009-07-19 19:37:11 +00:00
|
|
|
}
|
2009-06-15 13:36:12 +00:00
|
|
|
|
2009-07-14 21:13:23 +00:00
|
|
|
// Opera returns 0 when status is 304
|
2010-09-21 19:22:34 +00:00
|
|
|
return xhr.status === 304 || xhr.status === 0 && !xhr.getAllResponseHeaders();
|
2006-07-10 03:20:56 +00:00
|
|
|
},
|
2006-11-04 21:09:05 +00:00
|
|
|
|
2008-06-05 20:00:50 +00:00
|
|
|
httpData: function( xhr, type, s ) {
|
2010-01-06 15:19:38 +00:00
|
|
|
var ct = xhr.getResponseHeader("content-type") || "",
|
|
|
|
xml = type === "xml" || !type && ct.indexOf("xml") >= 0,
|
2008-05-15 21:03:31 +00:00
|
|
|
data = xml ? xhr.responseXML : xhr.responseText;
|
2007-07-21 00:52:30 +00:00
|
|
|
|
2009-07-19 19:37:11 +00:00
|
|
|
if ( xml && data.documentElement.nodeName === "parsererror" ) {
|
2010-01-23 21:48:47 +00:00
|
|
|
jQuery.error( "parsererror" );
|
2009-05-20 21:28:48 +00:00
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2008-05-16 16:39:27 +00:00
|
|
|
// Allow a pre-filtering function to sanitize the response
|
2009-07-19 19:37:11 +00:00
|
|
|
// s is checked to keep backwards compatibility
|
2009-05-20 21:28:48 +00:00
|
|
|
if ( s && s.dataFilter ) {
|
2008-06-05 20:00:50 +00:00
|
|
|
data = s.dataFilter( data, type );
|
2009-05-20 21:28:48 +00:00
|
|
|
}
|
2006-08-17 04:18:32 +00:00
|
|
|
|
2008-08-07 20:41:05 +00:00
|
|
|
// The filter can actually parse the response
|
2009-05-20 21:28:48 +00:00
|
|
|
if ( typeof data === "string" ) {
|
2008-08-07 20:41:05 +00:00
|
|
|
// Get the JavaScript object, if JSON is used.
|
2010-01-06 15:19:38 +00:00
|
|
|
if ( type === "json" || !type && ct.indexOf("json") >= 0 ) {
|
2010-01-23 21:51:51 +00:00
|
|
|
data = jQuery.parseJSON( data );
|
2010-01-07 17:21:58 +00:00
|
|
|
|
|
|
|
// If the type is "script", eval it in global context
|
|
|
|
} else if ( type === "script" || !type && ct.indexOf("javascript") >= 0 ) {
|
|
|
|
jQuery.globalEval( data );
|
2009-05-20 21:28:48 +00:00
|
|
|
}
|
2008-08-07 20:41:05 +00:00
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2006-08-17 04:18:32 +00:00
|
|
|
return data;
|
2010-01-25 05:46:03 +00:00
|
|
|
}
|
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-09-13 22:02:33 +00:00
|
|
|
// Does this browser support XHR requests?
|
|
|
|
jQuery.support.ajax = !!jQuery.ajaxSettings.xhr();
|
|
|
|
|
2010-03-02 15:44:48 +00:00
|
|
|
// For backwards compatibility
|
|
|
|
jQuery.extend( jQuery.ajax );
|
2010-09-08 17:54:33 +00:00
|
|
|
|
|
|
|
})( jQuery );
|