Ajax response event ? (Should be easy..)


#1

How do you call a javascript function to do something when the response
is returned to the visitors browser?

Easy ey?

//Daniel


#2

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


#3

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


#4

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