I can’t figure out why this doesn’t work, please help!! I just get the message “decoded =”
mydata = JSON.stringify(array_str_idnum);
$.ajax({
type: 'post',
cache: false,
url: 'parser.php',
data: mydata,
datatype: 'json',
success: function(msg){
$("#formstatus").ajaxComplete(function(){$(this).html(msg)});
}
});
<?php
// decode JSON string to PHP object
$decoded = json_decode($_POST['myJson'],true);
echo "decoded =";
echo $decoded;
?>
As
@Reanimationsuggests, you need to send the parameter that will hold the JSON data. I would recommend doing it more JavaScriptish way as:The other thing is that
$decodedwill actually hold an array as long as the originalarray_str_idnumis array, so doingecho $decodedwill outputArray(). Note also that the second paramerter tojson_decodeis to return the objects as associative arrays.