I'm trying to send my javascript object to PHP via JSON.stringify()
Javascript:
$('#save').on('click touch', function(){
obj = {
"1" : {
"1" : "hey",
"2" : "hay"
},
"2" : {
"1" : "hey",
"2" : "hay"
}
}
var json = JSON.stringify( obj );
console.log(json)
$.ajax({
type: 'POST',
url: 'ajax.php',
success: function(data) {
alert(data);
$("p").text(data);
}
});
});
ajax.php:
<?php
$obj = json_decode($json);
echo $obj;
?>
But this code returns an error saying that $json is not defined.
I have no idea why this is not working.
dataattribute on$.ajaxoptions.$_POSTvariable in PHPjsonvar in the ajax call...$_POST