Vote count:
0
Chrome console shows error when I send json_encode from php with defined keys, but works when I do not define keys:
"Uncaught SyntaxError: Unexpected token :"
This PHP ajax_return_array.php code works:
$array = array("a","b","c","d");
echo json_encode( $array );
This PHP jax_return_array.php code fails:
$array = array(1=>"a",2=>"b",3=>"c",4=>"d");
echo json_encode( $array );
jquery ajax:
$.ajax({
type: "POST",
url: "ajax_return_array.php",
success: function(result) {
if(result) {
resultObj = eval (result);
alert( resultObj );
} else {
alert("error");
}
}
});
asked 2 mins ago
Ajax json_encode error: "Uncaught SyntaxError: Unexpected token :" when returning array with keys
Aucun commentaire:
Enregistrer un commentaire