I'm trying to make a call to the database and recieve a "toplist" that is limited to 10 in PHP. Here I need to make an array and give it back to the Jquery with $.get().
But it's failing in recieving all the data with this code, How can I make this to be recieved and then do a "for each" in the Jquery for all the data that is being sent back from the PHP?
Jquery:
$.get("core.inc.php?get_toplist=1",
function(data) {
var json = JSON.parse(data);
alert(json['name']);
});
PHP:
if ($_GET['get_toplist']) {
$get_top_list = mysql_query("
SELECT * FROM ".$DBprefix."Submissions
WHERE status='1'
ORDER BY points DESC LIMIT 10");
$i = 0;
$arr = array();
while ($top_list = mysql_fetch_array($get_top_list)) {
$arr[] = array(
'position' => $i++,
'name' => $top_list['name'],
'points' => $top_list['points']
);
}
echo json_encode($arr);
}
alert()json_encode(), so it's returning JSON. The header doesn't have any effect on the data that's returned.JSON.parse()parses it.undefinedbecause the data returned is a multi dimensional array andnameis inside an inner node