$.ajax({
url: "http://www.xx.com",
method: "post",
headers: {
token: "test123"
},
data: JSON.stringify(postData),
success: function (data) {
console.log(data);
}
});
服务端代码如下:public function handle($request, \Closure $next)
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE");
header("Access-Control-Allow-Headers: Origin, Authorization, Content-Type, X-Requested-With, token");
header("Access-Control-Allow-Credentials: true");
if (strtoupper($request->method()) == "OPTIONS") {
return response();
}
return $next($request);
}
控制台报错:Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.我在服务端的Access-Control-Allow-Headers已经添加了token,但是请求的时候也报错了,有遇到过得嘛
最佳答案
