我在我的节点后端服务器验证码:AngularJS HTTP POST无法与节点服务器的工作
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
而这是API,即我要打电话:
router.post('/update/:_id', function(req, res, next) {
console.log("req.body:" + req.body);
}
这是我的帖子请求通过角1:
var data = {something: "something"}
var url = 'http://localhost:8081/update/5982168b399ccf32ad75ce2e';
$http({
withCredentials: false,
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: data
})
.then(function (response) {
if (response.data) {
console.log("Post Data Submitted Successfully!");
}
}, function (response) {
console.log("Error status: " + response.status)
});
我正在使用Angular 1.6.1版本。
我已经尝试了一切,并浏览了无数帖子,但没有人帮助我。我可以看到身体经历。但是我在节点端后端得到了undefined req.body
。
任何帮助,将不胜感激。
谢谢。
更改内容类型的应用程序/ json – Vivz
向你展示app.js(你调用'app.use'和路由)。 – alexmac
欢迎来到Stack Overflow!寻求调试帮助的问题(“为什么这个代码不工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。请参阅:如何创建[mcve]。使用“编辑”链接来改善你的*问题* - 不要通过评论添加更多信息。谢谢! – GhostCat