简体   繁体   中英

$http.post using AngularJS

I'd like to post an object using AngularJS but it doesn't work.

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
});

Main issue : I'm not able to recieve the POST request in my NodeJS controller using app.post and request.body .

NodeJS Controller :

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

I think the problem is with the link you are posting to, I wouldnt know how you are testing this, but if you are testing in your own server with localhost, you should post to

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

for testing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM