Hii I am working with angular2 and php. In my project I want to post the json into the php page , and access it in the server side . How can I make it possible??
in my angular2 , when I click on the button SaveData() will called.
SaveData()
{
const headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
let body = JSON.stringify(this.Cost);
this.http.post('http://192.168.0.100:80/php/test.php',body,{headers})
.subscribe(
data => console.log('Received:' + data),
err => console.log(err),
() => console.log('Call Complete')
);
}
an in my PHP page I used like..
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
$post = $_POST['body'];
$fp = fopen('a.txt', 'w');
fwrite($fp,$post);
fclose($fp);
?>
What is the best solution for this??