Access to XMLHttpRequest at ‘http://www.xiaoleql.com/api/login‘ from origin ‘http://localhost:8080‘

前端加上请求头token之后报错

Access to XMLHttpRequest at ‘http://www.xiaoleql.com/api/login‘ from origin ‘http://localhost:8080‘_第1张图片

 是因为后端没有配置

在php中加上这段配置即可

 header("Access-Control-Allow-Origin:*");
        header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
        header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding,token");
        if(request()->isOptions()){
            exit();
        }

Access to XMLHttpRequest at ‘http://www.xiaoleql.com/api/login‘ from origin ‘http://localhost:8080‘_第2张图片

你可能感兴趣的:(http,网络协议,网络)