X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=91043dedd1458b931f1702538b0fb8fa266684c3;hb=b1a40c9bfdbbfce5416e4dfa52577379bdcc0a74;hp=4135e34c41c5da055906a1b2f55667f6a1ec4fd9;hpb=0aa8d40cdfb50fd423a3bdcf585ac27f89df5b97;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 4135e34..91043de 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -3,7 +3,7 @@ jQuery.fn.extend({ _load: jQuery.fn.load, load: function( url, params, callback ) { - if ( typeof url != 'string' ) + if ( typeof url !== "string" ) return this._load( url ); var off = url.indexOf(" "); @@ -24,7 +24,7 @@ jQuery.fn.extend({ params = null; // Otherwise, build a param string - } else if( typeof params == 'object' ) { + } else if( typeof params === "object" ) { params = jQuery.param( params ); type = "POST"; } @@ -143,13 +143,15 @@ jQuery.extend({ url: location.href, global: true, type: "GET", - timeout: 0, contentType: "application/x-www-form-urlencoded", processData: true, async: true, + /* + timeout: 0, data: null, username: null, password: null, + */ // Create the request object; Microsoft failed to properly // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available // This function can be overriden by calling jQuery.ajaxSetup @@ -178,7 +180,7 @@ jQuery.extend({ type = s.type.toUpperCase(); // convert data if not already a string - if ( s.data && s.processData && typeof s.data != "string" ) + if ( s.data && s.processData && typeof s.data !== "string" ) s.data = jQuery.param(s.data); // Handle JSONP Parameter Callbacks @@ -265,6 +267,9 @@ jQuery.extend({ done = true; success(); complete(); + + // Handle memory leak in IE + script.onload = script.onreadystatechange = null; head.removeChild( script ); } }; @@ -378,6 +383,9 @@ jQuery.extend({ // Fire the complete handlers complete(); + if ( isTimeout ) + xhr.abort(); + // Stop memory leaks if ( s.async ) xhr = null; @@ -392,13 +400,8 @@ jQuery.extend({ if ( s.timeout > 0 ) setTimeout(function(){ // Check to see if the request is still happening - if ( xhr ) { - // Cancel the request - xhr.abort(); - - if( !requestDone ) - onreadystatechange( "timeout" ); - } + if ( xhr && !requestDone ) + onreadystatechange( "timeout" ); }, s.timeout); } @@ -458,8 +461,7 @@ jQuery.extend({ try { // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 return !xhr.status && location.protocol == "file:" || - ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 || - jQuery.browser.safari && xhr.status == undefined; + ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223; } catch(e){} return false; }, @@ -470,8 +472,7 @@ jQuery.extend({ var xhrRes = xhr.getResponseHeader("Last-Modified"); // Firefox always returns 200. check Last-Modified date - return xhr.status == 304 || xhrRes == jQuery.lastModified[url] || - jQuery.browser.safari && xhr.status == undefined; + return xhr.status == 304 || xhrRes == jQuery.lastModified[url]; } catch(e){} return false; }, @@ -490,7 +491,7 @@ jQuery.extend({ data = s.dataFilter( data, type ); // The filter can actually parse the response - if( typeof data == 'string' ){ + if( typeof data === "string" ){ // If the type is "script", eval it in global context if ( type == "script" ) @@ -498,7 +499,7 @@ jQuery.extend({ // Get the JavaScript object, if JSON is used. if ( type == "json" ) - data = eval("(" + data + ")"); + data = window["eval"]("(" + data + ")"); } return data;