Reputation: 7191
$http.post in Angularjs:-
$http({method: 'Post', url: '/signUp'} , {greeting: 'hi'}).
success(function(data, status, headers, config) {
alert(data);
});
Node- Express.js Server
app.post('/signUp', function (req, res){
res.send(req.body.greeting);
});
The angular code works fine. How do I receive {greeting: 'hi'} at the server?
req.body.greeting
is empty.
Upvotes: 0
Views: 965
Reputation: 19578
This should work fine if you change {method: 'Post', url: '/signUp'} , {greeting: 'hi'}
to
$http({method: 'Post', url: '/signUp', data: {greeting: 'hi'}}).
success(function(data, status, headers, config) {
alert(data);
});
Upvotes: 2