i'm new to JSON. I have a php with a multidimensional array which gets finally encoded in JSON format:
<?php
header('Content-Type: application/json');
$lista = array (
'Conoscenti'=>array (
0=>array(
"Nome"=>"John",
"Cognome"=>"Doe",
"Nato"=>array(
"Giorno"=>16,
"Mese"=>"Febbraio",
"Anno"=>1972
)
),
1=>array(
"Nome"=>"Elvis",
"Cognome"=>"Presley",
"Nato"=>array(
"Giorno"=>12,
"Mese"=>"Luglio",
"Anno"=>1984
)
),
2=>array(
"Nome"=>"Mick",
"Cognome"=>"Jagger",
"Nato"=>array(
"Giorno"=>13,
"Mese"=>"Novembre",
"Anno"=>1984
)
)
),
"Amici"=>array(
0=>array(
"Nome"=>"Michael",
"Cognome"=>"Myers",
"Nato"=>array(
"Giorno"=>8,
"Mese"=>"Dicembre",
"Anno"=>1986
)
),
1=>array(
"Nome"=>"Jim",
"Cognome"=>"Fear",
"Nato"=>array(
"Giorno"=>4,
"Mese"=>"Febbraio",
"Anno"=>1985
)
)
)
);
echo json_encode($lista);
?>
I want to load this through Ajax: to do this, i wrote some JQuery code:
var output ="<ul>";
$.ajax({
url:"lista.php",
dataType:"json"
}).done(function(data) {
$.each(data.Conoscenti, function() {
output +="<li>"+this.Nome+" "+this.Cognome+" è un mio conoscente. È nato il "+this.Nato.Giorno+" "+this.Nato.Mese+" "+this.Nato.Anno+"</li>";
});
});
output += "</ul>";
$("body").html(output);
But the html page shows blank, without even errors. Analyzing the source code it shows only the ul tag, since it's out of the ajax call. Anyone knows how can i fix it? Thank you.