Hi,

A submit button sends a form to the server, tearing down the current
document and window contents and replacing them with the response from
the server. You're scheduling asynchronous calls via setTimeout which
are then happening (or not happening) before and as the window is
being torn down as part of that form submission. That's not going to
work reliably. :-)

What is it you're actually trying to do?
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com


On Sep 28, 5:10 pm, mhgrove <mhgr...@gmail.com> wrote:
> I'll preface this with the fact that I am not much of a javascript
> hacker, and I'm new to prototype.  So the following might be a very
> dumb question, but I couldn't find an answer to this googling around,
> I'm hoping that maybe someone here can point out what I'm doing wrong.
>
> Basically, what I was trying to do before I got sidetracked trying to
> figure out why this didn't work is I have a form that the user will
> submit, the submission will usually take awhile, so rather than let
> the browser churn, I wanted to have the submit button call a function
> which would submit the form asynchronsously via an Ajax call, and then
> hide the submit button and replace it with a little spinner thing (I
> created one from ajaxload.info).
>
> In trying to do this, I kept getting the error "$ is not defined"
> which made very little sense because I was pulling prototype into my
> page the same way I do on other pages on my site and it works just
> fine.  After fumbling around I finally came up with the snippet of
> code pasted at the end of this email.
>
> I distilled my issue down to a button in a form, which calls a
> function.  This function schedules another call to what would display
> the spinner.  But for the purposes of trying to figure out what I'm
> doing wrong, I just have it printing the version of prototype.
>
> What I'm seeing on OSX with FF3.0 and 3.5 is that the behavior across
> clicks of the button is not consistent.  Sometimes I'll click it and
> see all three alerts, sometimes only two.  When I see only two, I get
> a "Prototype is not defined" error when it tries to display the third
> alert.  This same code seems to work fine on Safari 4.
>
> I tried some of the Function extensions of Prototype, but I get the
> same erratic behavior.
>
> Am I going about this the wrong way?
>
> Thanks.
>
> <!DOCTYPE html>
>
> <html>
>
> <head>
>     <script type="text/javascript" src="prototype.js"></script>
>     <script>
>     var timeoutId = -1;
>
>         function doClick() {
>             alert("dc prototype version: " + Prototype.Version);
>
>             timeoutId = setTimeout(next, 1);
> //            next.delay(0.1);
>  //           next.defer();
>   //          next.bind(this).defer();
>     //        next.bind(this).delay(0.1);
>       //      next.delay(1);
>         }
>
>         function next() {
>             alert("n1 prototype version: " + Prototype.Version);
>             alert("n2 prototype version: " + Prototype.Version);
>         }
>     </script>
> </head>
>
> <body>
>     <div>
>
>     <form>
>         <input type="submit" value="Click Me" onclick='doClick();'>
>     </form>
> </div>
> </body>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to