首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome给出“No 'Access-Control-Allow-Origin‘header is present on the requested error”,但firefox没有

Chrome给出“No 'Access-Control-Allow-Origin‘header is present on the requested error”,但firefox没有
EN

Stack Overflow用户
提问于 2017-06-28 19:14:53
回答 1查看 6K关注 0票数 0

我有这个脚本来获取创建JIRA REST API问题的字段元数据。这是我的要求:

代码语言:javascript
复制
$.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上运行时,我得到了错误:

代码语言:javascript
复制
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。但我认为这只是我正在开发的机器上的一种变通方法。那么最终用户呢?我不能期望他们都安装了这个扩展。

任何帮助都是非常感谢的。谢谢您:)

EN

回答 1

Stack Overflow用户

发布于 2017-06-28 19:23:25

大多数现代浏览器都会阻止对跨服务器的ajax调用。如果您有访问服务器的权限或需要寻找替代方案,则需要在服务器上启用CORS (跨域资源共享)。

你可以参考this的帖子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44800890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档