【发布时间】:2017-12-01 17:22:27
【问题描述】:
我有这个脚本来获取用于创建 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 上运行相同的脚本时,我没有收到此类错误。我读过关于 CORPS 的文章,我想我明白了。但我不明白为什么它适用于 Firefox,但不适用于 chrome。这是我必须忍受的铬合金吗?
我遇到了一些扩展或更改 chrome 设置以禁用 CORS。但我认为这只能在我正在开发的机器上解决。最终用户呢?我不能指望他们都安装了扩展。
感谢任何帮助。谢谢:)
【问题讨论】:
标签: jquery ajax google-chrome firefox