New version of mootools ajax timeout

Tuesday, March 25. 2008
1 comments
0 trackbacks

UPDATED

This does not work much better then the previous version, but it triggers a "real" event...

  1.  
  2. /*
  3. Class: Ajax
  4.         timeout for the ajax class
  5. Options:
  6.         timeout - timeout in milliseconds; default is none
  7.         onTimeout - timeout event
  8. Author:
  9.         Stefan Lange-Hegermann
  10. */
  11.  
  12. Ajax = Ajax.extend({
  13.         options: {
  14.                 onTimeout:Class.empty
  15.         },
  16.        
  17.     request: function(){
  18.     if (this.options.timeout) {
  19.         this.timeoutTimer=window.setTimeout(this.callTimeout.bindAsEventListener(this), this.options.timeout);
  20.         this.addEvent('onComplete', this.removeTimer);
  21.     }
  22.     this.parent();
  23.     },
  24.  
  25.     callTimeout: function () {
  26.         this.transport.abort();
  27.         this.onFailure();
  28.         this.fireEvent('onTimeout');
  29.     },
  30.  
  31.     removeTimer: function() {
  32.         window.clearTimeout(this.timeoutTimer);
  33.     }
  34. });
  35.  
by Stefan LH

Comments
Display comments as (Linear | Threaded)

Hi Stefan,

It looks like your request function unintentionally strips off the data payload that had been sent with the ajax request. A simple fix:

request: function(data){
if (this.options.timeout) {
    this.timeoutTimer=window.setTimeout(this.callTimeout.bindAsEventListener(this), this.options.timeout);
    this.addEvent('onComplete', this.removeTimer);
}
this.parent(data);
},
#1 Andrew Fuller (Homepage) on 2008-04-13 05:36 (Reply)

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/lang] tags to embed source code snippets
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed