Created
May 16, 2011 11:55
-
-
Save frodosghost/974316 to your computer and use it in GitHub Desktop.
Extending Ajax Request object for aborting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extend the Ajax.Request object to add function to abort() current Ajax Request | |
* | |
* @source http://blog.pothoven.net/2007/12/aborting-ajax-requests-for-prototypejs.html | |
*/ | |
Object.extend(Ajax.Request.prototype, { | |
abort: function() { | |
// prevent and state change callbacks from being issued | |
this.transport.onreadystatechange = Prototype.emptyFunction; | |
// abort the XHR | |
this.transport.abort(); | |
// update the request counter | |
Ajax.activeRequestCount--; | |
} | |
}); | |
Ajax.Responders.register({ | |
onComplete: function() | |
{ | |
if (Ajax.activeRequestCount < 0) Ajax.activeRequestCount = 0; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment