🌐 AI搜索 & 代理 主页
Skip to content

Commit fe6c86d

Browse files
committed
Experiment switching to using onreadystatechange rather than a setInterval for Ajax requests. Fixes #5735.
1 parent a00e63e commit fe6c86d

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

src/ajax.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -380,29 +380,21 @@ jQuery.extend({
380380
}
381381

382382
// Wait for a response to come back
383-
var onreadystatechange = function( isTimeout ) {
383+
var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
384384
// The request was aborted, clear the interval and decrement jQuery.active
385385
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" );
395392
}
396393

397394
// The transfer is complete and the data is available, or the request timed out
398395
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
399396
requestDone = true;
400-
401-
// clear poll interval
402-
if (ival) {
403-
clearInterval(ival);
404-
ival = null;
405-
}
397+
xhr.onreadystatechange = function(){};
406398

407399
status = isTimeout === "timeout" ?
408400
"timeout" :
@@ -446,19 +438,14 @@ jQuery.extend({
446438
}
447439
};
448440

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);
462449
}
463450

464451
// Send the data

0 commit comments

Comments
 (0)