我有index.html发送后请求到,localhost:3000/SetUser
但我总是收到错误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.
这是我的Angular控制器中的代码
$http.post("https://localhost:3000/SetUser", {'a':'b'}).success(function(data, status, headers, config) {
console.log('data', data);
});
这是我server.js(nodejs)上的代码 app.post
app.post('/SetUser', function(req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.end();
console.log("New user added ", req.body);
});
我尝试了所有操作,但现在不确定是否可以解决此问题。谢谢!
确保所有内容都在同一个端口上运行,并且应该能够解决问题,是的,通过他的错误,可以理解的是,他将请求从端口80发送到端口3000。是什么导致您无法在同一个端口上解析应用程序?
你应该更好地解释自己。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句