Sangram Singh
Sangram Singh

Reputation: 7191

Receiving 'data' of `$http.post('/someUrl', data).success` at server

$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

Answers (1)

Jayram
Jayram

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

Related Questions