Sunday, January 8, 2012

Rhomobile Ajax Calls using JQuery Mobile

Note: This will only work on IPhone,Android and Blackberry(version 6 and above) 

There is common scenario to use Ajax with Rhodes but I was not able to find good source to use them so thought of blogging it. I will be using Jquery Mobile framework which is by default with Rhodes.

In this example I will load some text inside a div on clicking of a button.

Step 1.) Create a div and button on a page
<input type= "button" id="some-button"/ name="button" value="Load Value By Ajax">
      <div id= "some-div">
      </div>


Step 2.) Create a Javascript 

Step 3.) Create a action ajax_method in controller
def ajax_method
    @some_value = "Its all about ruby ---" +@params['some_variable']
    render :action => :ajax_method, :layout => false, :use_layout_on_ajax => false
  end

Step 4.) Create a ajax_method.erb file
<i><b><%= @some_value %></b></i>

It is just a very basic example you can do many more things like error handling, adding loading image etc.



1 comment: