我刚刚发出一个 ajax post 请求,但收到如下错误:
XMLHttpRequest cannot load https://xxx.com?redirect_uri=http://www.example.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.
在这里我可以看到除了“www”之外,我的响应域和请求域没有任何不同,那么“www”也会导致这个问题吗?
最佳答案
问题是因为您正在发出跨域 AJAX 请求,该请求被浏览器安全性阻止 - 请参阅 Same Origin Policy .
该请求期望您向启用 CORS 的域发出请求,因此它会提示不存在的 header 。
您需要将请求更改为 jsonp
类型,或者使用服务器端代理来获取数据。
关于jquery - ajax post 请求是请求的资源上不存在 'Access-Control-Allow-Origin' header 。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20211093/