Forum: Rails Spinoffs (closed, excessive spam) Need "onTimeout" for Ajax class

Posted by Dan Delaney (Guest)
on 2008-06-26 20:38
(Received via mailing list)
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
Posted by Matt Foster (Guest)
on 2008-06-26 23:36
(Received via mailing list)
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
Posted by Matt Foster (Guest)
on 2008-06-26 23:52
(Received via mailing list)
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
Posted by kangax (Guest)
on 2008-06-27 02:07
(Received via mailing list)
Posted by Dan Delaney (Guest)
on 2008-06-27 18:24
(Received via mailing list)
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
Posted by kangax (Guest)
on 2008-06-27 21:37
(Received via mailing list)
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
Posted by Frederick Cheung (Guest)
on 2008-06-28 19:08
(Received via mailing list)
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
Posted by Matt Foster (Guest)
on 2008-06-30 22:09
(Received via mailing list)
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>
This topic is locked and can not be replied to.