我正在从不同的来源向我的服务器发出 Ajax POST 请求以供用户登录。我已经在 application_controller.rb 中正确设置了 Cross Origin 标头:
def set_access_control_headers
if request.options?
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Credentials'] = "true"
end
end
但我仍然得到:
XMLHttpRequest cannot load http://www.d1.com/sign_in. Origin http://www.d2.com is not allowed by Access-Control-Allow-Origin.