I\'m trying to record data that is being posted to my server to a text file. An example of the data that is being sent to my server is located here:
http://dev.data
To bypass the problem I used JSON.stringify.
'formSave' : function(project){
var s = {
"name": project.name,
"data": JSON.stringify(project.data)
};
$.post("sdcform/formSave/" + project.name, s);
}
The 'project' object contains the keys 'name' and 'data' and I only wanted to stringify the data part of it.
This way on the server I can do
$data = isset($_POST['data']) ? json_decode($_POST['data']): new \stdClass();
file_put_contents($filename, json_encode($data, JSON_PRETTY_PRINT));
I could store it directly to the file and save both conversion but I wanted to prettyfy it!
Note: Yes I know! Do not access $_POST directly.