1.Failed to load: http://url.com/main/info: Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.
由于前端的 AJAX 请求通常需要携带 token 验证,所以还需要将 token 添加到 Access-Control-Allow-Headers
解决方法:
将 header(‘Access-Control-Allow-Headers: content-type,token’); 添加到 入口文件 /public/index.php 即可。
2.tp5.1无法跨域请求
在public/index.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");