在https之间发送ajax请求

时间:2014-10-12 14:41:58

标签: ajax node.js angularjs http

我使用angular将ajax请求发送到nodejs文件,我发现此错误,

XMLHttpRequest cannot load https://localhost:3000/SetUser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost' is therefore not allowed access. 

将其从index.html发送到https://localhost:3000/SetUser,并指出可能出错的方法以及如何允许Access-Control-Allow-Origin访问?

- 编辑: 我用谷歌搜索,我发现了这一行

res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");

但我仍然得到同样的错误,这是当前的app.post

app.post('/SetUser', function(req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    console.log("New user added ", req.body);
});

谢谢!

0 个答案:

没有答案