我jsonapi-resources
在 Rails 中有一个后端 api。我能够使用curl
以及在 Python 中请求数据。
当我尝试使用jQuery
请求时,我在浏览器中收到以下错误:
XMLHttpRequest 无法加载 https://shop-api-3.herokuapp.com/customers?filter%5Bshop_token%5D=9e3c9769b752436ddbd27597cf946a36。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'null' 不允许访问。响应具有 HTTP 状态代码 404。
所以我将此添加到config/environments/production.rb
:
config.action_dispatch.default_headers = {
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept, Authorization',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => '*',
'X-Frame-Options' => 'ALLOWALL'
}
但是,我仍然遇到同样的错误。我错过了什么?
FWIW,这是我的curl
命令:
curl -i -H "Accept: application/vnd.api+json" "https://app.herokuapp.com/retentions?filter%5Bshop_token%
5D=ABC123"
使用 Rails 4