我在Rails應用程序有一個控制器,renderes得到JSON數據JSON數據如何從遠程應用程序
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
我我的其他應用程序,我做一個簡單的Ajax請求,從我的觀點
得到JSON字符串$.ajax({
url: 'http://url.com/show.json',
success: function(data){
console.log(data);
$('#data').html(data);
}
});
的跨域頭,我使用機架一個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
我不是從阿賈克斯[R gwetting任何東西eQUEST的。任何想法爲什麼這可能發生?
是你的部分文件命名是否正確? _this.json.erb? – 2012-04-26 19:07:07