X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=7bd392aa2374a8837713d9b711da8334142f0238;hb=2a921daaa7a02a73967e51b9e09037f667af5af7;hp=d8494d3fb25ae0195637d324c03e6ac6ba9b3ef2;hpb=5ec5de6953a22b33de46897c8e915eed300338e6;p=jquery.git diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index d8494d3..7bd392a 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -58,7 +58,7 @@ jQuery.fn.load = function( url, params, callback, ifModified ) { }; // If IE is used, create a wrapper for the XMLHttpRequest object -if ( jQuery.browser.msie ) +if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function(){ return new ActiveXObject( navigator.userAgent.indexOf("MSIE 5") >= 0 ? @@ -144,6 +144,8 @@ jQuery.extend({ // Watch for a new set of requests if ( ! jQuery.active++ ) jQuery.event.trigger( "ajaxStart" ); + + var requestDone = false; // Create the request object var xml = new XMLHttpRequest(); @@ -170,8 +172,10 @@ jQuery.extend({ // Wait for a response to come back var onreadystatechange = function(istimeout){ // The transfer is complete and the data is available, or the request timed out - if ( xml && (xml.readyState == 4 || istimeout) ) { - var status = jQuery.httpSuccess( xml ) && !istimeout ? + if ( xml && (xml.readyState == 4 || istimeout == "timeout") ) { + requestDone = true; + + var status = jQuery.httpSuccess( xml ) && istimeout != "timeout" ? ifModified && jQuery.httpNotModified( xml, url ) ? "notmodified" : "success" : "error"; // Make sure that the request was successful or notmodified @@ -221,8 +225,7 @@ jQuery.extend({ // Cancel the request xml.abort(); - // for Opera. Opera does't call onreadystatechange when aborted. - if (xml) onreadystatechange(1); + if ( !requestDone ) onreadystatechange( "timeout" ); // Clear from memory xml = null; @@ -239,9 +242,9 @@ jQuery.extend({ // Determines if an XMLHttpRequest was successful or not httpSuccess: function(r) { try { - return r.status ? - ( r.status >= 200 && r.status < 300 ) || r.status == 304 : - location.protocol == "file:"; + return !r.status && location.protocol == "file:" || + ( r.status >= 200 && r.status < 300 ) || r.status == 304 || + jQuery.browser.safari && r.status == undefined; } catch(e){} return false; @@ -253,7 +256,8 @@ jQuery.extend({ var xmlRes = xml.getResponseHeader("Last-Modified"); // Firefox always returns 200. check Last-Modified date - if( xml.status == 304 || xmlRes == jQuery.lastModified[url] ) return true; + return xml.status == 304 || xmlRes == jQuery.lastModified[url] || + jQuery.browser.safari && xml.status == undefined; } catch(e){} return false; @@ -264,12 +268,15 @@ jQuery.extend({ // otherwise return plain text. httpData: function(r,type) { var ct = r.getResponseHeader("content-type"); - var data = ( !type || type == "xml" ) && ct && ct.indexOf("xml") >= 0; - data = data ? r.responseXML : r.responseText; + var data = !type && ct && ct.indexOf("xml") >= 0; + data = type == "xml" || data ? r.responseXML : r.responseText; // If the type is "script", eval it if ( type == "script" ) eval.call( window, data ); + // Get the JavaScript object, if JSON is used. + if ( type == "json" ) eval( "data = " + data ); + return data; },