リモートアプリから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
私私の他のアプリ私は私の見解
からJSON文字列を取得するための簡単なAJAX要求を行いますクロスドメインヘッダの$.ajax({
url: 'http://url.com/show.json',
success: function(data){
console.log(data);
$('#data').html(data);
}
});
私が使用私はAjaxのrから戻って何かをgwettingないです
use Rack::Cors do
allow do
origins '*'
# regular expressions can be used here
resource '/countvisit/*', :headers => :any, :methods => :any
# headers to expose
end
end
ラックCORS平等。なぜこれが起こるかもしれないの任意のアイデア?
あなたの部分ファイルは正しく名前が付けられていますか? _this.json.erb? –