Forum: Ruby on Rails ajax response event ? (Should be easy..)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel (Guest)
on 2006-03-24 23:13
How do you call a javascript function to do something when the response
is returned to the visitors browser?

Easy ey?

//Daniel
Ben R. (Guest)
on 2006-03-25 00:08
(Received via mailing list)
Many of the built-in AJAX actions in Rails such as the link_to_remote
allow you to specify JavaScript to execute upon completion by setting
the :success attribute.  In this example, I show the spinner div while
the processing occurs, and hide it when it is complete.

<%= link_to_remote( "#{state.title}",
    :update => "state_editor",
    :before => %(Element.show('spinner')),
    :success => %(Element.hide('spinner')) ,
    :url =>{ :action => "load_state", :id => state.id }) %>

Hope this helps ~

Ben

On 3/24/06, Daniel <removed_email_address@domain.invalid> wrote:
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben R.
http://www.benr75.com
Daniel (Guest)
on 2006-03-27 18:39
Thanks, thats what Im looking for.

Could someone please elaborate on how to override the setting of
success/failure attribute?

Thanks in advance

// Daniel

Ben R. wrote:
> Many of the built-in AJAX actions in Rails such as the link_to_remote
> allow you to specify JavaScript to execute upon completion by setting
> the :success attribute.  In this example, I show the spinner div while
> the processing occurs, and hide it when it is complete.
>
> <%= link_to_remote( "#{state.title}",
>     :update => "state_editor",
>     :before => %(Element.show('spinner')),
>     :success => %(Element.hide('spinner')) ,
>     :url =>{ :action => "load_state", :id => state.id }) %>
>
> Hope this helps ~
>
> Ben
>
> On 3/24/06, Daniel <removed_email_address@domain.invalid> wrote:
>> Rails mailing list
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Ben R.
> http://www.benr75.com
Daniel (Guest)
on 2006-03-27 19:13
More info on what Im trying to do:

I submit a login form using ajax.
On the server side I check if the submitted info is valid.
Depending on if the submitted info is valid or not I send back different
partials.

If the info was invalid I would like to set the failure attribute so
that I can pop up a javascript alert in the browser.

Is this doable?

//Daniel
This topic is locked and can not be replied to.