Ruby on Rails Webservice - access via ajax request

I implement a server in ruby ​​on rails. Now I want to get some data from this server using an ajax request (the client side is in a different domain, so this is a cross-domain call) and accepts the data as JSON.

What do I need to do to make this work?

thank

+3
source share
3 answers

Use client side jquery to send ajax requests:

Create a from your parameters, for example:

var data = {
                    remote: true,
                    myplace:
                    {
                        swlat:lat(),
                        swlng:lng(),
                        nelat:lat(),
                        nelng:lng(),

                    }
                };
    $.getJSON('/location/getNewLocation',data, function(postsData) {
       parseReturnedJsonData(postsData);

   });

POST URL- json-. , json, jQuery parseReturnedJsonData(). getJson parseJson jQuery: http://api.jquery.com/jQuery.getJSON/

+1

callback :

  $.getJSON('http://some-service.com/some-resource?callback=?',data, function(postsData) {
    parseReturnedJsonData(postsData);
  });

, , API, , JSONP. http://eduvoyage.com/jsonp-explained.html, , JSONP.

0

All Articles