OPTIONS
在跨域的时候,浏览器会自动发起一个OPTIONS请求。
在请求的时候即使设置了允许跨域访问,有可能还是会访问失败,出现403、504等错误
如下:
XMLHttpRequest cannot load http://xxx.xx.com. Response to preflight request doesn't
pass access control check: No 'Access-Control-Allow-Origin' header is present on
the requested resource. Origin 'http://xxx.xx.com' is therefore not allowed access.
The response had HTTP status code 403.
解决办法:
添加以下配置
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin http://qaservice.365bencao.cn;
add_header Access-Control-Allow-Headers Origin,X-Requested-With,Content-Type,Accept;
return 200;
}
......
}