Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域

天启 后端 前端 2019-05-28

跨域错误提示:

XMLHttpRequest cannot load http://xxx.com. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

解决方案:

php服务端程序设置头:

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, x-file-name");
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE');

其实主要是看console返回的错误信息,适当修改以上代码的参数。哪个被拒绝了,就添加哪一个。

评论

技术博客发布平台

只服务于

前后端、移动端、测试人员

写博客