0

I have this function (angular) to send information to php page:

public SendData(cart_items:any) {
  const jsonContent = new RequestOptions({
    headers:new Headers({ 
        'Content-Type': 'application/json' 
    })
  });
  let body = JSON.stringify(cart_items);
        return this.http.post("xxxxxxxxxx/pay.php", body, jsonContent)
            .map(result => {
            return result.json();
        }); 
    }

how can i get access to data in the page 'pay.php'

Fray
  • 250
  • 2
  • 5
  • 16

1 Answers1

2

This is more of a pure php question, but you do this:

 $json = file_get_contents('php://input');
    $obj = json_decode($json, true);
    $name = $obj['name'];
    $age = $obj['age'];

This would work if the object you're posting is like this: { "name":"My Name", "age":"24" }

Kevin
  • 827
  • 1
  • 7
  • 18