Has anyone discussed adding an "onTimeout" option for Ajax.Request?
That would be incredibly useful. Something like this would be great:
new Ajax.Request('/someurl', { onSuccess: doSomething, timeoutDelay:
10000, onTimeout: doSomethingElse });
timeoutDelay, of course, is milliseconds, as in the
window.setTimeout() method.
Cheers
--Dan
on 2008-06-26 20:38
on 2008-06-26 23:36
Hey Dan,
You know, I can't even count how many times a lingering modal
has locked an ajax application that I've been using or working on.
Every other request worked fine, but for some reason this one is lost
in space, who knows where those packets have gone, and at this point
who cares. A respectable recovery would be ideal, but in many cases
the application is "locked" during these load times, so not only has
your request failed, but now your client is compromised. I've
implemented some things to get around this idea, but for some reason
reading your post got me motivated to do some serious monkey
patching. Its a pretty cool idea and I've got it working really well,
only a minimal amount of refactoring was necessary, it wasn't even
half as hard as i expected and wrote the code and did testing this
afternoon. For my basic examples it worked fine. Some behind the
scenes stuff you may need to know in my example is that the
responder.php script is just executing "sleep(delay)" delay being the
variable that you send it. Also as with most of my "examples" you
gotta read the code and look at your console in firebug to see whats
actually going on.
The example
http://positionabsolute.net/projects/javascript/AjaxTimeout/
My monkey patched version of proto 1.6
http://positionabsolute.net/includes/javascripts/p...
--
Matt Foster
Ajax Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
on 2008-06-26 23:52
Kind of a strange nuance I just noted was that, when the transport is aborted, the Ajax.Request deems it as a success. Looking into the Ajax.Request.success method, it has right upfront in the condition (! status || ... ) so that makes a status of 0 a success, really? This seems strange now but im sure there is a very good reason. In my refactoring i removed that part of the condition, seemed to test out ok but be forewarned. -- Matt Foster Ajax Engineer Nth Penguin, LLC http://www.nthpenguin.com
on 2008-06-27 02:07
You might want to take a look at: http://dev.rubyonrails.org/ticket/10191 http://dev.rubyonrails.org/ticket/10030 http://dev.rubyonrails.org/ticket/3730 -- kangax
on 2008-06-27 18:24
On Jun 26, 8:06 pm, kangax <kan...@gmail.com> wrote: > You might want to take a look at: > http://dev.rubyonrails.org/ticket/10191 > http://dev.rubyonrails.org/ticket/10030 > http://dev.rubyonrails.org/ticket/3730 Thanks Kangax. Those first two don't have anything to do with a Timeout function, but the last one is a patch that does EXACTLY what I described in the OP! Unfortunately, the patch was submitted two YEARS ago, didn't work in Safari, and so was never included in prototype. Maybe I'll download the patch and see if I can get it working in Safari. Or maybe Matt would like to take a look at it. He seems awfully motivated :-) Thanks for that monkey patch, Matt. I can't express enough how incredibly useful it would be to be able to set a separate timeout period and function for each Ajax.Request. --Dan
on 2008-06-27 21:37
Yes, it would indeed be useful. There are plans for some ajax refactoring in 1.6.1. Most of these annoyances will most likely be fixed. -- kangax
on 2008-06-28 19:08
There's a ticket here: http://prototype.lighthouseapp.com/projects/8886/t... that added a timeout. It was suggested that it was better left as a plugin. The thing I'd really like to know is why a status of 0 counts as success. If anyone can cast some light on that one I'd be very grateful! Fred
on 2008-06-30 22:09
I have been testing this quite a bit and I've come up with my own question now. Is it useful to have a separate event handler for the onTimeout event, or does it make more sense to just abort the request and fire the onFailure event, as in any case, if the request times out, its failed, hasn't it? -- Matt Foster Ajax Engineer Nth Penguin, LLC http://www.nthpenguin.com On Jun 28, 1:07 pm, Frederick Cheung <frederick.che...@gmail.com>