Searched around and couldn't seem to find an answer. I am using ajax to post this stringified array filled with objects, which JSONLint's alright to a php script which right now just returns it.
However over the transmission the object turns into NULL. Is there something wrong with the way I'm sending my string of JSON? I would really appreciate some advice for this, will give out virtual high fives. Thanks for your time!
JS
var newDist = $("#distanceEl").val();
var newDate = $("#dateEl").val();
var newId = this.arr.length + 1;
var newStat = new Stat(newId, newDist, newDate);
this.arr.push(newStat);
var newData = JSON.stringify(this.arr);
console.log(newData);
$.ajax({
url : "php/post.php",
type: "POST",
dataType : "json",
contentType : "application/json",
data: newData,
success: function(response)
{
console.log("Ajax: " + JSON.parse(response));
},
error: function(requestObject, error, errorThrown)
{
console.log("Error with Ajax Post Request:" + error);
console.log(errorThrown);
}
});
PHP
$jsonData = json_decode($_POST['newData']);
echo json_encode($jsonData);