【发布时间】:2016-08-24 09:00:10
【问题描述】:
我正在使用 Eve 和 AngularJS 中的 API 开发应用程序。
为了避免 CORS 问题,我制作了一个简单的 NodeJS 服务器来提供我的静态文件。
但是,即使在通过编写'X_DOMAINS': '*'(我使用 Curl 测试并且它有效)允许我的 Python Eve API 上的所有域之后,当我想使用 $http 调用 API 时,我的浏览器中也遇到了问题。
这是我在 chrome 中遇到的错误:
XMLHttpRequest cannot load http://localhost:5000/regions. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
我什至在我的 Node 应用程序中写了这个,尽管我认为它没有用:
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
res.header("Access-Control-Allow-Methods", "GET, POST","PUT");
next();
});
到目前为止没有任何效果,提前感谢您的帮助!
【问题讨论】:
标签: python angularjs node.js cors eve