Reputation: 24472
I'm trying to send a post request from angular 2 to a php file.
Unfortunetly, when trying to var_dump($_POST)
, I see an empty array.
This is my angular 2 post:
addPerson(name)
{
let body = JSON.stringify({
name : name,
});
this.http.request(this.BASE_URL + "mode=add", {body:body, method: 'POST'})
.subscribe(
response => {
console.log(response.json());
},
error => {
console.log(error.text());
}
);
}
In my PHP File I just tried to var_dump($_POST)
.
What am I missing?
Upvotes: 1
Views: 663
Reputation: 136144
I'm not sure why you used http.request
. You could call HTTP
post method directly, that seems simpler and more readable.
this.http.post(this.BASE_URL + "mode=add", body)
Upvotes: 1