1:
Error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
解决:
在后端设置 headers(因为现在是用自己写的后台做一个小的测试) Access-Control-Allow-Origin: *
(其实应该有很多别的解决方法, 但是我赶时间, 就先这样搞定测试一下,以后遇到了慢慢来~)
比如
express:
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Type, Accept');
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
// res.header("Content-Type", "application/json;charset=utf-8");
res.header("Content-Type", "application/json;charset=utf-8");
2:
Error:
Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
解决:
修改后端的Access-Control-Allow-Headers
比如我的:
从
res.header("Access-Control-Allow-Headers", 'Content-Type’)
=》
res.header("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Type, Accept');
至于为什么,我之后看看,现在只是记录一下哈!!!
附上 Web Docs网址,感兴趣有时间就好好进去看一看,肯定比我讲得好