我有这个脚本来获取创建JIRA REST API问题的字段元数据。这是我的要求:
$.ajax({
url:"https://jira.nutanix.com/rest/api/2/issue/createmeta",
headers: { 'Access-Control-Allow-Origin': '*' },
headers: {'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS'},
headers: { 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token' },
type: "GET",
success: function (result) {
console.log(result);
}
});当它在chrome上运行时,我得到了错误:
XMLHttpRequest cannot load https://jira.nutanix.com/rest/api/2/issue/createmeta. 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:63342' is therefore not allowed access.但是,当我在firefox上运行相同的脚本时,我没有得到这样的错误。我读过关于“军团”的书,我想我理解它。但我不明白为什么它能在火狐上运行,却不能在chrome上运行。这是我不得不忍受的铬元素吗?
我遇到过一些扩展或改变chrome设置来禁用CORS。但我认为这只是我正在开发的机器上的一种变通方法。那么最终用户呢?我不能期望他们都安装了这个扩展。
任何帮助都是非常感谢的。谢谢您:)
发布于 2017-06-28 19:23:25
大多数现代浏览器都会阻止对跨服务器的ajax调用。如果您有访问服务器的权限或需要寻找替代方案,则需要在服务器上启用CORS (跨域资源共享)。
你可以参考this的帖子。
https://stackoverflow.com/questions/44800890
复制相似问题