X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax.js;h=1dc781477d8df38a98f2a9ae39a82417a71a2699;hb=31f22f244be7c37cc7a22f390d3483c9680b6b58;hp=b90ca16cbc4076b69b0811afec201b96cc890a9e;hpb=46931d3146b454298231fc80a6c2d3894b125fde;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index b90ca16..1dc7814 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,7 +1,10 @@ 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 ) { @@ -68,8 +71,8 @@ jQuery.fn.extend({ 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){ @@ -100,7 +103,7 @@ jQuery.extend({ callback = data; data = null; } - + return jQuery.ajax({ type: "GET", url: url, @@ -138,6 +141,7 @@ jQuery.extend({ }, ajaxSettings: { + url: location.href, global: true, type: "GET", timeout: 0, @@ -156,7 +160,7 @@ jQuery.extend({ _default: "*/*" } }, - + // Last-Modified header cache for next request lastModified: {}, @@ -230,9 +234,13 @@ jQuery.extend({ 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 ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && 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; @@ -245,7 +253,7 @@ jQuery.extend({ // 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(); @@ -268,7 +276,11 @@ jQuery.extend({ var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); // Open the socket - xml.open(s.type, s.url, s.async, s.username, s.password); + // Passing null username, generates a login popup on Opera (#2865) + if( s.username ) + xml.open(s.type, s.url, s.async, s.username, s.password); + else + xml.open(s.type, s.url, s.async); // Need an extra try/catch for cross domain requests in Firefox 3 try { @@ -298,7 +310,7 @@ jQuery.extend({ xml.abort(); return false; } - + if ( s.global ) jQuery.event.trigger("ajaxSend", [xml, s]); @@ -307,13 +319,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; - + // 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" || @@ -336,13 +348,13 @@ jQuery.extend({ 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 ) - success(); + success(); } else jQuery.handleError(s, xml, status); @@ -354,10 +366,10 @@ jQuery.extend({ xml = null; } }; - + 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 ) @@ -366,20 +378,20 @@ jQuery.extend({ if ( xml ) { // Cancel the request xml.abort(); - + if( !requestDone ) onreadystatechange( "timeout" ); } }, s.timeout); } - + // 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(); @@ -407,7 +419,7 @@ jQuery.extend({ if ( s.global && ! --jQuery.active ) jQuery.event.trigger( "ajaxStop" ); } - + // return XMLHttpRequest to allow aborting the request etc. return xml; },