Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Experiment switching to using onreadystatechange rather than a setInt…

…erval for Ajax requests. Fixes #5735.
  • Loading branch information...
commit fe6c86d53046b0f4d648f61c0b8e75387af65152 1 parent a00e63e
John Resig authored

Showing 1 changed file with 16 additions and 29 deletions. Show diff stats Hide diff stats

  1. 45  src/ajax.js
45  src/ajax.js
@@ -380,29 +380,21 @@ jQuery.extend({
380 380
 		}
381 381
 
382 382
 		// Wait for a response to come back
383  
-		var onreadystatechange = function( isTimeout ) {
  383
+		var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
384 384
 			// The request was aborted, clear the interval and decrement jQuery.active
385 385
 			if ( !xhr || xhr.readyState === 0 ) {
386  
-				if ( ival ) {
387  
-					// clear poll interval
388  
-					clearInterval( ival );
389  
-					ival = null;
390  
-
391  
-					// Handle the global AJAX counter
392  
-					if ( s.global && ! --jQuery.active ) {
393  
-						jQuery.event.trigger( "ajaxStop" );
394  
-					}
  386
+				requestDone = true;
  387
+				xhr.onreadystatechange = function(){};
  388
+
  389
+				// Handle the global AJAX counter
  390
+				if ( s.global && ! --jQuery.active ) {
  391
+					jQuery.event.trigger( "ajaxStop" );
395 392
 				}
396 393
 
397 394
 			// The transfer is complete and the data is available, or the request timed out
398 395
 			} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
399 396
 				requestDone = true;
400  
-
401  
-				// clear poll interval
402  
-				if (ival) {
403  
-					clearInterval(ival);
404  
-					ival = null;
405  
-				}
  397
+				xhr.onreadystatechange = function(){};
406 398
 
407 399
 				status = isTimeout === "timeout" ?
408 400
 					"timeout" :
@@ -446,19 +438,14 @@ jQuery.extend({
446 438
 			}
447 439
 		};
448 440
 
449  
-		if ( s.async ) {
450  
-			// don't attach the handler to the request, just poll it instead
451  
-			var ival = setInterval(onreadystatechange, 13);
452  
-
453  
-			// Timeout checker
454  
-			if ( s.timeout > 0 ) {
455  
-				setTimeout(function() {
456  
-					// Check to see if the request is still happening
457  
-					if ( xhr && !requestDone ) {
458  
-						onreadystatechange( "timeout" );
459  
-					}
460  
-				}, s.timeout);
461  
-			}
  441
+		// Timeout checker
  442
+		if ( s.async && s.timeout > 0 ) {
  443
+			setTimeout(function() {
  444
+				// Check to see if the request is still happening
  445
+				if ( xhr && !requestDone ) {
  446
+					onreadystatechange( "timeout" );
  447
+				}
  448
+			}, s.timeout);
462 449
 		}
463 450
 
464 451
 		// Send the data

0 notes on commit fe6c86d

Please sign in to comment.
Something went wrong with that request. Please try again.