Railsアプリに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);
}
});
クロスドメイン ヘッダーには、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
私は ajax リクエストから何も返しません。なぜこれが起こるのでしょうか??