How do you call a javascript function to do something when the response is returned to the visitors browser? Easy ey? //Daniel -- Posted via http://www.ruby-forum.com/.
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:> How do you call a javascript function to do something when the response > is returned to the visitors browser? > > Easy ey? > > //Daniel > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com
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-- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.