Mootools AJAX timeout
Who needs descriptions? This adds a timeout option to the mootools Ajax class...
Ajax = Ajax.extend({
request: function(){
if (this.options.timeout) {
this.timeoutTimer=window.setTimeout(this.callTimeout.bindAsEventListener(this), this.options.timeout);
this.addEvent('onComplete', this.removeTimer);
}
this.parent();
},
callTimeout: function () {
this.transport.abort();
this.onFailure();
if (this.options.onTimeout) {
this.options.onTimeout();
}
},
removeTimer: function() {
window.clearTimeout(this.timeoutTimer);
}
});
You can call it like this:
var myAjax = new Ajax('lengthy.php', {method: 'get', update: $('content'), timeout: 2000, onTimeout: function() {alert('timeout')}}).request();
by Stefan LH




You can also do Ajax = Ajax.extend to use the same class + this.parent support.
I should have thought of that. Changed it. Thanks!
Ah, nice, thank you... I'd develop something like that for my old prototype framework, but yours fit a lot better with mootools
Great stuff
I was going to code something similar for my MOOdalBox, but your implementation is leaner and cleaner tham what I had in mind
With your permission, I will include it in the upcoming release, and you will be mentioned both in the source code and on the homepage.
You can sure use the ajax timeout script for MOOdalBox. I hereby declare, that it's in the public domain.
your code crash at ie7, i think you sholud not run 'this.parent();' before you addEvent.
that's my fix:
Nice! Here is a slightly modified version to work with Ajax.remote:
nice!