$ http.post使用AngularJS

时间:2017-01-06 16:13:56

标签: angularjs node.js express

我想使用AngularJS发布一个对象,但它不起作用。

console.log(user); // {firstname: 'toto', lastname: 'tutu'}

$http.post('/user/create', user).then(function(response) {
  console.log(response); // undefined
}, function(error) {
  console.log(error); // undefined
});

主要问题:我无法使用app.postrequest.body在我的NodeJS控制器中收到POST请求。

NodeJS控制器:

app.post('/user/create', function(request, response) {
    console.log(request.body); // undefined
});

1 个答案:

答案 0 :(得分:0)

我认为问题在于您发布的链接,我不知道您是如何测试的,但如果您使用localhost在自己的服务器上进行测试,则应该发布到

"http://localhost:(portNumberYouOpenedForExpress)/user/create" 

进行测试

相关问题