Index: src/ajax.js =================================================================== --- src/ajax.js (revision 3533) +++ src/ajax.js (working copy) @@ -78,6 +78,7 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), { initialize: function(url, options) { this.transport = Ajax.getTransport(); + this.aborted = false; this.setOptions(options); this.request(url); }, @@ -103,6 +104,10 @@ this.setRequestHeaders(); + if (this.options.requestTimeout) + this.requestTimer = setTimeout((function() {this.abortRequest()}).bind(this), + this.options.requestTimeout * 1000); + var body = this.options.postBody ? this.options.postBody : parameters; this.transport.send(this.options.method == 'post' ? body : null); @@ -111,6 +116,11 @@ } }, + abortRequest: function() { + this.aborted = true; + this.transport.abort(); + }, + setRequestHeaders: function() { var requestHeaders = ['X-Requested-With', 'XMLHttpRequest', @@ -166,25 +176,33 @@ var transport = this.transport, json = this.evalJSON(); if (event == 'Complete') { + if (this.requestTimer) + clearTimeout(this.requestTimer); + try { - (this.options['on' + this.transport.status] - || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] - || Prototype.emptyFunction)(transport, json); + if (!this.aborted) { + (this.options['on' + this.transport.status] + || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] + || Prototype.emptyFunction)(transport, json); + } else { + (this.options['onTimeout'] + || Prototype.emptyFunction)(transport, json); + } } catch (e) { this.dispatchException(e); } - + if ((this.header('Content-type') || '').match(/^text\/javascript/i)) this.evalResponse(); } - + try { (this.options['on' + event] || Prototype.emptyFunction)(transport, json); Ajax.Responders.dispatch('on' + event, this, transport, json); } catch (e) { this.dispatchException(e); } - + /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ if (event == 'Complete') this.transport.onreadystatechange = Prototype.emptyFunction; Index: CHANGELOG =================================================================== --- CHANGELOG (revision 3533) +++ CHANGELOG (working copy) @@ -1,5 +1,7 @@ *SVN* +* Add requestTimeout option to Ajax.Request [Todd Ross] + * Fix Enumerable.zip iterator behavior. [Marcin Kaszynski, sam] *1.5.0_pre0* (January 18, 2006)