git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
jquery ajax: closes #2842.
[jquery.git]
/
src
/
ajax.js
diff --git
a/src/ajax.js
b/src/ajax.js
index
0f799fc
..
bf6c464
100644
(file)
--- a/
src/ajax.js
+++ b/
src/ajax.js
@@
-1,7
+1,10
@@
jQuery.fn.extend({
jQuery.fn.extend({
+ // Keep a copy of the old load
+ _load: jQuery.fn.load,
+
load: function( url, params, callback ) {
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 off = url.indexOf(" ");
if ( off >= 0 ) {
@@
-68,8
+71,8
@@
jQuery.fn.extend({
jQuery.makeArray(this.elements) : this;
})
.filter(function(){
jQuery.makeArray(this.elements) : this;
})
.filter(function(){
- return this.name && !this.disabled &&
- (this.checked || /select|textarea/i.test(this.nodeName) ||
+ return this.name && !this.disabled &&
+ (this.checked || /select|textarea/i.test(this.nodeName) ||
/text|hidden|password/i.test(this.type));
})
.map(function(i, elem){
/text|hidden|password/i.test(this.type));
})
.map(function(i, elem){
@@
-91,7
+94,7
@@
jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp
};
});
};
});
-var jsc = (new Date).getTime();
+var jsc = now();
jQuery.extend({
get: function( url, data, callback, type ) {
jQuery.extend({
get: function( url, data, callback, type ) {
@@
-100,7
+103,7
@@
jQuery.extend({
callback = data;
data = null;
}
callback = data;
data = null;
}
-
+
return jQuery.ajax({
type: "GET",
url: url,
return jQuery.ajax({
type: "GET",
url: url,
@@
-138,6
+141,7
@@
jQuery.extend({
},
ajaxSettings: {
},
ajaxSettings: {
+ url: location.href,
global: true,
type: "GET",
timeout: 0,
global: true,
type: "GET",
timeout: 0,
@@
-156,7
+160,7
@@
jQuery.extend({
_default: "*/*"
}
},
_default: "*/*"
}
},
-
+
// Last-Modified header cache for next request
lastModified: {},
// Last-Modified header cache for next request
lastModified: {},
@@
-211,7
+215,7
@@
jQuery.extend({
s.cache = false;
if ( s.cache === false && s.type.toLowerCase() == "get" ) {
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
// try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
// if nothing was replaced, add timestamp to the end
@@
-230,9
+234,13
@@
jQuery.extend({
if ( s.global && ! jQuery.active++ )
jQuery.event.trigger( "ajaxStart" );
if ( s.global && ! jQuery.active++ )
jQuery.event.trigger( "ajaxStart" );
+ // Matches an absolute URL, and saves the domain
+ var remote = /^(?:\w+:)?\/\/([^\/?#]+)/;
+
// If we're requesting a remote document
// and trying to load JSON or Script with a GET
// 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.dataType == "script" && s.type.toLowerCase() == "get"
+ && remote.test(s.url) && remote.exec(s.url)[1] != location.host ){
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
@@
-245,7
+253,7
@@
jQuery.extend({
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
- if ( !done && (!this.readyState ||
+ if ( !done && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
success();
this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
success();
@@
-291,9
+299,14
@@
jQuery.extend({
} catch(e){}
// Allow custom headers/mimetypes
} 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]);
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
@@
-302,13
+315,13
@@
jQuery.extend({
// The transfer is complete and the data is available, or the request timed out
if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
// The transfer is complete and the data is available, or the request timed out
if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
-
+
// clear poll interval
if (ival) {
clearInterval(ival);
ival = null;
}
// clear poll interval
if (ival) {
clearInterval(ival);
ival = null;
}
-
+
status = isTimeout == "timeout" && "timeout" ||
!jQuery.httpSuccess( xml ) && "error" ||
s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
status = isTimeout == "timeout" && "timeout" ||
!jQuery.httpSuccess( xml ) && "error" ||
s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
@@
-331,13
+344,13
@@
jQuery.extend({
try {
modRes = xml.getResponseHeader("Last-Modified");
} catch(e) {} // swallow exception thrown by FF if header is not available
try {
modRes = xml.getResponseHeader("Last-Modified");
} catch(e) {} // swallow exception thrown by FF if header is not available
-
+
if ( s.ifModified && modRes )
jQuery.lastModified[s.url] = modRes;
// JSONP handles its own success callback
if ( !jsonp )
if ( s.ifModified && modRes )
jQuery.lastModified[s.url] = modRes;
// JSONP handles its own success callback
if ( !jsonp )
- success();
+ success();
} else
jQuery.handleError(s, xml, status);
} else
jQuery.handleError(s, xml, status);
@@
-349,10
+362,10
@@
jQuery.extend({
xml = null;
}
};
xml = null;
}
};
-
+
if ( s.async ) {
// don't attach the handler to the request, just poll it instead
if ( s.async ) {
// don't attach the handler to the request, just poll it instead
- var ival = setInterval(onreadystatechange, 13);
+ var ival = setInterval(onreadystatechange, 13);
// Timeout checker
if ( s.timeout > 0 )
// Timeout checker
if ( s.timeout > 0 )
@@
-361,20
+374,20
@@
jQuery.extend({
if ( xml ) {
// Cancel the request
xml.abort();
if ( xml ) {
// Cancel the request
xml.abort();
-
+
if( !requestDone )
onreadystatechange( "timeout" );
}
}, s.timeout);
}
if( !requestDone )
onreadystatechange( "timeout" );
}
}, s.timeout);
}
-
+
// Send the data
try {
xml.send(s.data);
} catch(e) {
jQuery.handleError(s, xml, null, e);
}
// Send the data
try {
xml.send(s.data);
} catch(e) {
jQuery.handleError(s, xml, null, e);
}
-
+
// firefox 1.5 doesn't fire statechange for sync requests
if ( !s.async )
onreadystatechange();
// firefox 1.5 doesn't fire statechange for sync requests
if ( !s.async )
onreadystatechange();
@@
-402,7
+415,7
@@
jQuery.extend({
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
}
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
}
-
+
// return XMLHttpRequest to allow aborting the request etc.
return xml;
},
// return XMLHttpRequest to allow aborting the request etc.
return xml;
},
@@
-443,9
+456,9
@@
jQuery.extend({
},
httpData: function( r, type ) {
},
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";
if ( xml && data.documentElement.tagName == "parsererror" )
throw "parsererror";
@@
-484,7
+497,7
@@
jQuery.extend({
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
});
else
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, "+");
// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");