Skip to content

Instantly share code, notes, and snippets.

@frodosghost
Created May 16, 2011 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frodosghost/974316 to your computer and use it in GitHub Desktop.
Save frodosghost/974316 to your computer and use it in GitHub Desktop.
Extending Ajax Request object for aborting
/**
* 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