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.
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-03-24 22:13
How do you call a javascript function to do something when the response
is returned to the visitors browser?

Easy ey?

//Daniel
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-03-24 23: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 <big@chello.se> wrote:
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben Reubenstein
http://www.benr75.com
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-03-27 16: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 Reubenstein 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 <big@chello.se> wrote:
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Ben Reubenstein
> http://www.benr75.com
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-03-27 17: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.