Experiment switching to using onreadystatechange rather than a setInterval for Ajax requests. Fixes #5735.
This commit is contained in:
parent
a00e63ea5a
commit
fe6c86d530
1 changed files with 15 additions and 28 deletions
23
src/ajax.js
23
src/ajax.js
|
@ -380,29 +380,21 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a response to come back
|
// 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
|
// The request was aborted, clear the interval and decrement jQuery.active
|
||||||
if ( !xhr || xhr.readyState === 0 ) {
|
if ( !xhr || xhr.readyState === 0 ) {
|
||||||
if ( ival ) {
|
requestDone = true;
|
||||||
// clear poll interval
|
xhr.onreadystatechange = function(){};
|
||||||
clearInterval( ival );
|
|
||||||
ival = null;
|
|
||||||
|
|
||||||
// Handle the global AJAX counter
|
// Handle the global AJAX counter
|
||||||
if ( s.global && ! --jQuery.active ) {
|
if ( s.global && ! --jQuery.active ) {
|
||||||
jQuery.event.trigger( "ajaxStop" );
|
jQuery.event.trigger( "ajaxStop" );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// The transfer is complete and the data is available, or the request timed out
|
// The transfer is complete and the data is available, or the request timed out
|
||||||
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
|
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
|
||||||
requestDone = true;
|
requestDone = true;
|
||||||
|
xhr.onreadystatechange = function(){};
|
||||||
// clear poll interval
|
|
||||||
if (ival) {
|
|
||||||
clearInterval(ival);
|
|
||||||
ival = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = isTimeout === "timeout" ?
|
status = isTimeout === "timeout" ?
|
||||||
"timeout" :
|
"timeout" :
|
||||||
|
@ -446,12 +438,8 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( s.async ) {
|
|
||||||
// don't attach the handler to the request, just poll it instead
|
|
||||||
var ival = setInterval(onreadystatechange, 13);
|
|
||||||
|
|
||||||
// Timeout checker
|
// Timeout checker
|
||||||
if ( s.timeout > 0 ) {
|
if ( s.async && s.timeout > 0 ) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
// Check to see if the request is still happening
|
// Check to see if the request is still happening
|
||||||
if ( xhr && !requestDone ) {
|
if ( xhr && !requestDone ) {
|
||||||
|
@ -459,7 +447,6 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
}, s.timeout);
|
}, s.timeout);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Send the data
|
// Send the data
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue