Has someone come up with a generic way to handle ajax requests that exceed a certain time? In my concrete case, I have several select boxes for drilling down a hierarchy. When the user clicks an option, the next deeper level is retrieved. To avoid multiple concurrent requests, I disable the select box. As the request may take too long or cause an error, I set a timeout that re-enables the select boxes. Now, this isn''t really complicated, but it makes my code just slightly messier. What I''d like best is to have a two options on Ajax: timeoutDelay and onTimeout, where on a timeout the request is aborted. Does the base XmlHttpRequest support this in any way? A very quick web search didn''t bring up any relevant info. Michael -- Michael Schuerig Most people would rather die than think. mailto:michael@schuerig.de In fact, they do. http://www.schuerig.de/michael/ --Bertrand Russell
On 13/08/05, Michael Schuerig <michael@schuerig.de> wrote:> What I''d like best is to have a two options on Ajax: > timeoutDelay and onTimeout, where on a timeout the request is aborted. > Does the base XmlHttpRequest support this in any way? A very quick web > search didn''t bring up any relevant info.I don''t think it can do this by itself. The code at http://www.ajaxtoolbox.com/ has both properties by means of setTimeout. BTW: The API of the thing is very good, nice features. Check out the "Activity Monitoring" example. One can get a callback when any request starts and when the last (parallel) running request finishes. I use this as in AjaxRequestBegin = function (){ document.body.style.cursor = "wait"; } AjaxRequestEnd = function (){ document.body.style.cursor = ""; } so I don''t turn the cursor back only after there no request left running. And you can group requests and have these Begin/End functions for them. Maybe worthwhile to adapt? Bye, Martin
On Saturday 13 August 2005 13:25, Martin Bialasinski wrote:> On 13/08/05, Michael Schuerig <michael@schuerig.de> wrote: > > What I''d like best is to have a two options on Ajax: > > timeoutDelay and onTimeout, where on a timeout the request is > > aborted. Does the base XmlHttpRequest support this in any way? A > > very quick web search didn''t bring up any relevant info. > > I don''t think it can do this by itself. The code at > http://www.ajaxtoolbox.com/ has both properties by means of > setTimeout.[snip]> Maybe worthwhile to adapt?I try to "standardize" on prototype.js. The past hour I''ve been trying to put timeout handling in there, without much success. The core is easy, of course. The consequences are nasty, however, as other code building on Ajax.Request expects a fully functional XHR object in their handlers which I can''t give them on timeout. Adding timeout there would probably break too much dependend code. Thus I stick with handling it in my own code. Michael -- Michael Schuerig They tell you that the darkness mailto:michael@schuerig.de Is a blessing in disguise http://www.schuerig.de/michael/ --Janis Ian, From Me To You
On 13/08/05, Michael Schuerig <michael@schuerig.de> wrote:> On Saturday 13 August 2005 13:25, Martin Bialasinski wrote:> > http://www.ajaxtoolbox.com/ has both properties by means of > > setTimeout. > > Maybe worthwhile to adapt?> I try to "standardize" on prototype.js.Yeah, I rather ment "implement the ideas from ajaxtoolbox into controls.js" :-)> The past hour I''ve been trying > to put timeout handling in there, without much success.Sorry, can''t help you there. I didn''t look into the AJAX stuff in controls yet. Bye, Martin
On Saturday 13 August 2005 21:47, Martin Bialasinski wrote:> On 13/08/05, Michael Schuerig <michael@schuerig.de> wrote: > > On Saturday 13 August 2005 13:25, Martin Bialasinski wrote: > > > http://www.ajaxtoolbox.com/ has both properties by means of > > > setTimeout. > > > Maybe worthwhile to adapt? > > > > I try to "standardize" on prototype.js. > > Yeah, I rather ment "implement the ideas from ajaxtoolbox into > controls.js" :-)I''m not using controls.js... I would love to, but the major drawback for me is that most of the time I need more than just text; in addition, I need an id/foreign key. I''ve got my own widgets for this, mostly using select elements. They''re not nearly as stylish as Thomas''s controls and if it were possible, I''d switch instantly. Michael -- Michael Schuerig Thinking is trying to make up mailto:michael@schuerig.de for a gap in one''s education. http://www.schuerig.de/michael/ --Gilbert Ryle