1
I have this ajax request:
$.ajax({
type: "POST",
url: "retorno.php",
success: function(data){
alert(data["nome"]);
},
error: function(erro){
alert(erro);
}
})
And the return.php file:
<?php
$teste=array();
$teste["nome"]="nometeste";
$teste["idade"]="aa";
$a=json_encode($teste);
echo $a;
?>
The return.php results in:
{
"nome":"nometeste",
"idade":"aa"
}
But in the jQuery
, within the request ajax
, both the data["nome"]
as to the data["idade"]
return undefinided
.
What might be going on?
It’s irrelevant to use
data["nome"]
ordata.nome
, "Navigation by JSON object occurs with dot" is not 100% correct. The problem here was to adddataType: 'json'
, for the ajax to return an object.– Sergio