跨域问题

浏览:556 发布日期:2020/03/21 分类:求助交流 关键字: thinkphp5.1 跨域 ajax
前台ajax请求如下:$.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,但是请求的时候也报错了,有遇到过得嘛
最佳答案
评论( 相关
后面还有条评论,点击查看>>