TheUnreal
TheUnreal

Reputation: 24472

Angular 2 post request to php file

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

Answers (1)

Pankaj Parkar
Pankaj Parkar

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

Related Questions