今、Backboneはすぐに使用できるクロスドメイン呼び出しをサポートしていないことがわかりました。
Backbone.jsはクロスドメイン呼び出しを「サポート」します。実際、これはbackbone.jsに固有のものではなく、それをサポートするブラウザーの役割です。CORS互換ブラウザでは、各リクエスト(POST、GET)の前にOPTIONSリクエストがあり、サーバーが対応するPOSTまたはGETリクエストを承認しているかどうかを確認します。
したがって、Railsアプリケーションでこの新しい呼び出しに応答する必要があります。例えば :
class ApplicationController < ActionController::Base
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Max-Age'] = "1728000"
end
# If this is a preflight OPTIONS request, then short-circuit the
# request, return only the necessary headers and return an empty
# text/plain.
def cors_preflight_check
if request.method == :options
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
headers['Access-Control-Max-Age'] = '1728000'
render :text => '', :content_type => 'text/plain'
end
end
end
この素晴らしい投稿からのコード:http ://www.tsheffler.com/blog/?p = 428
したがって、Nginxプラグインが正常に機能する場合は、問題ないはずです。Access-Control-Allow-Origin
ヘッダーにJavaScriptが実行されるドメインが含まれていることを確認してください。