Hi Tobie,

Ah, thank you--that looks very much like what I want (I didn't know
that method was there!). I just have one problem: I want the AJAX to
post to a different script than the normal form would go to. Since
Form#request() takes its URL from the form's action, which is not the
script the AJAX should go to, I would need to change that somehow. I
suppose I could hack it and change the action attribute with
writeAttribute() before AJAX, then change it back afterwards and hope
that Form#request() gets the action at the right time (or set a
timeout), but I would hope there's a better way to override the URL it
requests. Do you know of such a way? I don't see it in the list of
standard Ajax#request() options.

Thank you very much,

Turner



On Dec 29, 5:08 am, Tobie Langel <[EMAIL PROTECTED]> wrote:
> I've re-read your initial post. It appears that you are stopping the
> event from your onSuccess callback, that's abviously way too late
> (remember, the "a" in ajax stands for asynchronous).
>
> In pseudo code, your observer should look something like this:
>
> $('my_form').observe('submit', function(event) {
>   var valid = validate();
>   if (!valid) return;
>   this.request({onSuccess: someFunc}) // this stands for your form
> element here. seehttp://prototypejs.org/api/form/request
>   event.stop();
>
> });
>
> Best,
>
> Tobie
>
> On Dec 29, 10:27 am, Turner <[EMAIL PROTECTED]> wrote:
>
> > Hi Tobie,
>
> > I feel appropriately foolish for that. I <i>know</i> about onsubmit--
> > why did I choose onclick? Bah. Well, I'm sad to report that, after
> > changing all my relevant observations to 'submit', I am still getting
> > the same results. It seems that should have done the trick, but sadly,
> > not. Thank you for your tip, though.
>
> > Turner
>
> > On Dec 29, 3:51 am, Tobie Langel <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > You should be observing the form's submit event not the submit
> > > button's click event.
>
> > > Best,
>
> > > Tobie
>
> > > On Dec 29, 8:19 am, Turner <[EMAIL PROTECTED]> wrote:
>
> > > > I've just started using Prototype, and it's mostly been pretty good to
> > > > me. I just have one strange problem. I'm observing a click event on a
> > > > comment submit button in order to run a function before it submits a
> > > > form. That function, among other things like validation, submits an
> > > > AJAX request to add to the database. The idea is that it should do the
> > > > AJAX request if the browser supports it and then stop the event from
> > > > submitting the form (if there is no AJAX support, it should go ahead
> > > > and submit it).
>
> > > > So I'm using Prototype's Ajax functions, and I have an onSuccess
> > > > function that does its stuff with the server response and then stops
> > > > the event using event.stop(). Well, I'm having mixed results--the AJAX
> > > > goes through fine, but the form is still being submitted, in addition
> > > > to the AJAX request. The event claims to be stopped (that is,
> > > > event.stopped is true after I call event.stop(), as it should be), so
> > > > it doesn't seem like a bug there (besides, I tried calling
> > > > event.preventDefault() just in case, and got the same results). Not
> > > > that I thought it would be, but you know, try everything, right?
>
> > > > Anyway, this is pissing me off and after hours of debugging I have
> > > > gotten no results. Of course, this probably means that it's some
> > > > ridiculously trivial fencepost error or something of that nature, but
> > > > I thought maybe someone here would have some idea of what could be
> > > > going wrong.
>
> > > > Oh, and I get this behavior on IE7 (Windows Vista) and Firefox
> > > > 2.0.0.11 (Vista and Ubuntu). Haven't tested other browsers.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to