CORS 问题请求的资源上不存在“访问控制允许源头" [英] CORS problems no 'access control allow origin header' is present on the requested resource
问题描述
这就是我想要做的:
function fetch() {
$http.get("http://www.myapifilms.com/imdb/top")
.success(function(response) {
console.log(response);
$scope.details = response;
});
};
我收到的错误如下:
XMLHttpRequest 无法加载 http://www.myapifilms.com/imdb/top.请求的资源上不存在Access-Control-Allow-Origin"标头.Origin 'http://localhost:3000' 因此不允许访问.
XMLHttpRequest cannot load http://www.myapifilms.com/imdb/top. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
我在这个问题或 CORS 上查了很多,但似乎仍然无法意识到我必须添加什么以及在哪个文件中.
I've looked up quite a bit on this issue or CORS but still can't seem to realize what i have to add and in which file(s).
推荐答案
这意味着 http://www.myapifilms.com 不允许localhost"来源访问其数据.
This means that http://www.myapifilms.com does not allow "localhost" origin to access its data.
我可以推荐两种解决方案:
I could recommend two solutions:
通过运行
npm install -g http-server
下载 chrome 插件(不推荐)但可以方便地进行测试 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-信息对话框
download a chrome plugin(not recommended) but can be handy for testing https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-info-dialog
这篇关于CORS 问题请求的资源上不存在“访问控制允许源头"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!