I have this ajax request:
$.ajax({
type: "POST",
url: "retorno.php",
success: function(data){
alert(data["nome"]);
},
error: function(erro){
alert(erro);
}
})
And the file return.php:
<?php
$teste=array();
$teste["nome"]="nometeste";
$teste["idade"]="aa";
$a=json_encode($teste);
echo $a;
?>
Returns.php results in:
{
"nome":"nometeste",
"idade":"aa"
}
But in jQuery
, within ajax
, both data["nome"]
and data["idade"]
return undefinided
.
What could be happening?