我有2个在不同子域上运行的应用程序。 backend.website.com frontend.website.com
前端调用后端并为用户检索数据。这适用于所有浏览器,并且适用于Edge 18及更高版本。
使用Edge 18时,出现406个错误
Request URL: http://backend.website.com/api
Request Method: OPTIONS
Status code: 406 / No matching accepted Response format could be determined
backend.website.com上的我的NGINX配置
location / {
index app.php;
try_files $uri @rewriteapp;
add_header Access-Control-Allow-Origin http://frontend.website.com;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,x-auth';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'http://frontend.website.com';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, HEAD, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' 'http://frontend.website.com';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, HEAD, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,x-auth';
}
}
我的前端ajax配置
var settings = {
"async": true,
"method": "GET",
"crossDomain": true,
"url": "http://backend.website.com",
}