jQuery.fn.extend({
+ // Keep a copy of the old load
+ _load: jQuery.fn.load,
+
load: function( url, params, callback ) {
- if ( jQuery.isFunction( url ) )
- return this.bind("load", url);
+ if ( typeof url != 'string' )
+ return this._load( url );
var off = url.indexOf(" ");
if ( off >= 0 ) {
};
});
-var jsc = (new Date).getTime();
+var jsc = now();
jQuery.extend({
get: function( url, data, callback, type ) {
script: "text/javascript, application/javascript",
json: "application/json, text/javascript",
text: "text/plain",
- "default": "*/*"
+ _default: "*/*"
}
},
s.cache = false;
if ( s.cache === false && s.type.toLowerCase() == "get" ) {
- var ts = (new Date()).getTime();
+ var ts = now();
// try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
// if nothing was replaced, add timestamp to the end
// If we're requesting a remote document
// and trying to load JSON or Script with a GET
- if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) {
+ if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && s.type.toLowerCase() == "get" ) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
// Set the Accepts header for the server, depending on the dataType
xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
s.accepts[ s.dataType ] + ", */*" :
- s.accepts.default );
+ s.accepts._default );
} catch(e){}
// Allow custom headers/mimetypes
- if ( s.beforeSend )
- s.beforeSend(xml);
-
+ if ( s.beforeSend && s.beforeSend(xml, s) === false ) {
+ // cleanup active request counter
+ s.global && jQuery.active--;
+ // close opended socket
+ xml.abort();
+ return false;
+ }
+
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
},
httpData: function( r, type ) {
- var ct = r.getResponseHeader("content-type");
- var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
- var data = xml ? r.responseXML : r.responseText;
+ var ct = r.getResponseHeader("content-type"),
+ xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
+ data = xml ? r.responseXML : r.responseText;
if ( xml && data.documentElement.tagName == "parsererror" )
throw "parsererror";
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
});
else
- s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
+ s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");