I\'ve tried out all examples I could get my hands on, yet I can\'t simply save JSON data to a JSON file on my host. I want to start with a simple as possible save method so
$.ajax
alone will not save the json file, you need to direct the url
property to a server-side script, i.e. http://your.host/save_json.php
, that will create general.json
and write your output on it. Something like:
PHP:
<?php
$myFile = "general.json";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $_GET["data"];
fwrite($fh, $stringData);
fclose($fh)
?>
You'll also need to change the data
property in your ajax
call to data: {data: JSON.stringify(eventsholded)}
to give the GET variable a proper name that can be retrieved from PHP:
JQUERY
$.ajax
({
type: "GET",
dataType : 'json',
async: false,
url: 'http://your.host/save_json.php',
data: { data: JSON.stringify(eventsholded) },
success: function () {alert("Thanks!"); },
failure: function() {alert("Error!");}
});