I'm using jQuery and jquery-json to post data to a PHP script.
$.post('<?php echo url_for('/ajax.php'); ?>', 'data=' + $.toJSON(order), function (response) {
if (response == "success") {
$("#respond").html('<div class="success">Item Saved!</div>').hide().fadeIn(1000);
setTimeout(function () {
$('#respond').fadeOut(1000);
}, 2000);
}
})
If I console.log(order) I get the following JOSN:
{"details":[{"template_id":"25","font_size":"22"}]}
In my ajax.php file I have:
$data = json_decode($_POST["data"]);
var_dump($data);exit;
Which returns 'NULL'
But when I have the following code:
$data = $_POST["data"];
var_dump($data);exit;
It returns:
string(61) "{\"details\":[{\"template_id\":\"25\",\"font_size\":\"26\"}]}"
Is there any reason why it is escaped?
What is the easiest way to decode this?
Thanks