aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2008-11-14 04:16:00 +0000
committerJohn Resig <jeresig@gmail.com>2008-11-14 04:16:00 +0000
commit0aa8d40cdfb50fd423a3bdcf585ac27f89df5b97 (patch)
tree84695360a49056be261716f9fef7974d3d556e6f /src/ajax.js
parent464535e0965d5de617a24e608a2d05393194c3fd (diff)
downloadjquery-0aa8d40cdfb50fd423a3bdcf585ac27f89df5b97.tar.gz
jquery-0aa8d40cdfb50fd423a3bdcf585ac27f89df5b97.zip
Landing fixes for tickets #2935 and #2688 (Aborting ajax doesn't stop the setInterval, ajaxStop event isn't getting triggered).
Diffstat (limited to 'src/ajax.js')
-rw-r--r--src/ajax.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/ajax.js b/src/ajax.js
index 7e024a319..4135e34c4 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -308,10 +308,11 @@ jQuery.extend({
s.accepts._default );
} catch(e){}
- // Allow custom headers/mimetypes
+ // Allow custom headers/mimetypes and early abort
if ( s.beforeSend && s.beforeSend(xhr, s) === false ) {
- // cleanup active request counter
- s.global && jQuery.active--;
+ // Handle the global AJAX counter
+ if ( s.global && ! --jQuery.active )
+ jQuery.event.trigger( "ajaxStop" );
// close opended socket
xhr.abort();
return false;
@@ -322,8 +323,18 @@ jQuery.extend({
// Wait for a response to come back
var onreadystatechange = function(isTimeout){
+ // The request was aborted, clear the interval and decrement jQuery.active
+ if (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" );
+ }
// The transfer is complete and the data is available, or the request timed out
- if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) {
+ } else if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
// clear poll interval