Wednesday, February 2, 2011

How to make a remote call synchronous in Rails

new Ajax.Request('/controller/action?username=praveen', {asynchronous:false, evalScripts:true, parameters:'page_offset=' + page_offset + '&authenticity_token=' + encodeURIComponent('e060znd6JcrMCU6Bf4ZZnfyBac4tl1YXQ6HuEHZGY58=')});

What to do to get that "asynchronous:false" thing in your link_to_remote or any other helper function available in rails :)

I know its not a big thing and there is/are very few requirements to make an Ajax call synchronous but one might face this requirement sometimes, and the answers is
<%=remote_function(:url => {:controller => "controller", :action => "action", :username => "praveen"}, :type => :synchronous, :with => "'page_offset=' + page_offset") -%>

And you are done... so now till the time this thing is taking place, everything in browser will be waiting to complete the process first and then only proceed next.
Hope you stumble on me looking in for me.

1 comment:

The baffling IQ test

Getting 100 per cent means you “have a passion for perfection and you like to challenge yourself. You excel in finding problems and solutio...