X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=182a88e5a7f6572dfcba7431971d208736c0ec02;hb=b2289f3ec174c5b22d130d8c36a5e07daa6d02df;hp=098a5615203b2bf1a24c1e3df3cf5412a556b3fc;hpb=39518945047413f1185682078043e70e0c5c9091;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 098a561..182a88e 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -175,12 +175,13 @@ jQuery.extend({ traditional: false, */ // Create the request object; Microsoft failed to properly - // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available + // implement the XMLHttpRequest in IE7 (can't request local files), + // so we use the ActiveXObject when it is available // This function can be overriden by calling jQuery.ajaxSetup xhr: function() { - return window.ActiveXObject ? - new ActiveXObject("Microsoft.XMLHTTP") : - new XMLHttpRequest(); + return window.XMLHttpRequest && window.location.protocol !== "file:" || window.ActiveXObject ? + new window.XMLHttpRequest() : + new window.ActiveXObject("Microsoft.XMLHTTP"); }, accepts: { xml: "application/xml, text/xml", @@ -380,29 +381,21 @@ jQuery.extend({ } // Wait for a response to come back - var onreadystatechange = function( isTimeout ) { + var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) { // The request was aborted, clear the interval and decrement jQuery.active if ( !xhr || xhr.readyState === 0 ) { - if ( ival ) { - // clear poll interval - clearInterval( ival ); - ival = null; - - // Handle the global AJAX counter - if ( s.global && ! --jQuery.active ) { - jQuery.event.trigger( "ajaxStop" ); - } + requestDone = true; + xhr.onreadystatechange = jQuery.noop; + + // Handle the global AJAX counter + if ( s.global && ! --jQuery.active ) { + jQuery.event.trigger( "ajaxStop" ); } // The transfer is complete and the data is available, or the request timed out } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) { requestDone = true; - - // clear poll interval - if (ival) { - clearInterval(ival); - ival = null; - } + xhr.onreadystatechange = jQuery.noop; status = isTimeout === "timeout" ? "timeout" : @@ -446,19 +439,14 @@ jQuery.extend({ } }; - if ( s.async ) { - // don't attach the handler to the request, just poll it instead - var ival = setInterval(onreadystatechange, 13); - - // Timeout checker - if ( s.timeout > 0 ) { - setTimeout(function() { - // Check to see if the request is still happening - if ( xhr && !requestDone ) { - onreadystatechange( "timeout" ); - } - }, s.timeout); - } + // 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); } // Send the data