Could anyone tell me why the following statement does not send the post data to the designated url? The url is called but on the server when I print $_POST - I get an empty
I had the same problem with AngularJS and Node.js + Express 4 + Router
Router expects the data from post's request in body. This body was always empty if i followed the example from Angular Docs
Notation 1
$http.post('/someUrl', {msg:'hello word!'})
But if i used it in the data
Notation 2
$http({
withCredentials: false,
method: 'post',
url: yourUrl,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: postData
});
Edit 1:
Otherwise node.js router will expect the data in req.body if used notation 1:
req.body.msg
Which also sends the information as JSON payload. This is better in some cases where you have arrays in your json and x-www-form-urlencoded will give some problems.
it worked. Hope it helps.