sebastien
sebastien

Reputation: 11

Ajax asynchronous in ruby helpers

I'd like to know how to run an asynchronous ajax request through a ruby on rails helper. To be more specific, I need to call remote_function:

remote_function  :url => { :action => "draw_graph" }, :after => "do_something_after_ajax_is_done()" }

But do_something_after_ajax_is_done() is executing while ajax request is running and it mess up my plans.

I thought of using :async => false or :asynchronous => false option but it does not seem to work. Could you help me on the syntax or tell me what is wrong with my way of doing it.

Is remote_function even taking option for asynchronous option?

Upvotes: 1

Views: 350

Answers (1)

Matt Powell
Matt Powell

Reputation: 109

I think you want :complete

  remote_function  :url => { :action => "draw_graph" }, :complete => "do_something_after_ajax_is_done();"

this will run when the Ajax request has returned. If you only want to run if it's successful, use :success

  remote_function  :url => { :action => "draw_graph" }, :success => "do_something_after_ajax_is_done();"

Upvotes: 2

Related Questions