現在我發現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的域。