I currently am getting a 200 green response, however my data is still NOT being written to my json file (i.e. it is still blank)
The JavaScript:
$(function() {
$('form#saveTemp').submit(function() {
let savdAta = JSON.stringify($('form#saveTemp').serializeObject());
//let tempName = savdAta.styleName;
console.log(savdAta);
//console.log(JSON.stringify($('form#saveTemp').serializeObject()));
$.ajax({
url: './php/data.php',
type: 'POST',
contentType: "application/json",
data: {
template: savdAta
},
success: function(msg) {
console.log('data sent to php file, but..');
}
});
return false;
});
});
data in console from savdAta
is in below format: i.e.
{"styleName":"","fillType":"none","fillTrans":"0"}
PHP:
<?php
header('Content-Type: application/json');
if (!isset($_POST['savdAta']) && !empty($_POST['savdAta'])) {
$savdAta = $_POST['savdAta'];
$jsonObject = json_encode($savdAta);
file_put_contents('./data.json', $jsonObject);
}
Update: Now I have the below, with no errors, and yet still my .json file is blank:
<?php
if (!empty($_POST['template'])) {
$savdAta = $_POST['template'];
file_put_contents('./data.json', $savdAta);
}