I'm a noob struggling with something relativly simple (or so I believe). Writing an json or more precisly geojson object to a file with jquery ajax. My approach looks like this so far
$.ajax({
type: 'POST',
url: "data/markers.geojson", //url of receiver file on server
data: data, //geojson data
dataType: "json"
});
Looks fine, I think, but unfortunately the markers.geojson file remains completely empty. If I log the content of the data variable to the console right before the '$.ajax' it's all there. And the network console shows that bytes are transfered.
Now after searching a lot I noticed that everybody else seems to be sending json data not to a .json file but a .php file. Unfortunately they all seem to do other stuff on the php side or nobody deems it necessary to post the method to save the received json to a file on the server.
Alas, I'm a beginner and could really need some help here - how should the .php file look to just save the json to a file?
EDIT This answer in the other question solved the problem:
<?php
$myFile = "testFile.txt";
$phpObj = json_decode($_POST['json']);
file_put_contents($myFile,$phpObj);
echo '{ "success": true }';
?>
- just don't forget to enable php in your apache ;-) And again thanks to the patient @ADyson to walk a beginner through this.