Leon
Leon

Reputation: 1292

How to get Json data from a remote app

i have a controller in my rails app that renderes json data

def show
 @visit = Visit.all
 @count = @visit.first.count unless @visit == [] 
 respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @visit.first }
  format.json {render :partial => "this.json"}
 end
end

i my other app i do a simple ajax request to get the json string from my view

$.ajax({
url: 'http://url.com/show.json', 
success: function( data ){
    console.log(data);
  $('#data').html(data);
 }
});​

for the crossdomain headers i use Rack Cors

use Rack::Cors do
 allow do
  origins '*'
  # regular expressions can be used here
  resource '/countvisit/*', :headers => :any, :methods => :any
  # headers to expose
 end
end

I am not gwetting anything back from the ajax request. Any idea of why this might happen??

Upvotes: 0

Views: 478

Answers (1)

Andión
Andión

Reputation: 1113

You are trying to render 'this.json' partial and not the actual json string.

Shouldn't it be format.json {render :json=> "this.json"} instead?

Upvotes: 2

Related Questions