I am making an HTTP message request in Javascript to update a JSON file.
function updateJson(dataNew){
var stringData = JSON.stringify(dataNew);
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'update.php',
data: {stringData},
success : function(d){
alert('done');}
})
}
Then in PHP:
<?php
$a = json_encode(file_get_contents("php://input"));
file_put_contents('newData.json', $a);
?>
I want JSON data in a JSON file, however the json file contains only one line, similar to the payload of an http message message. What am I doing wrong?
source
share