I am using the Scoreoid platform to implement a leaderboard. The following is my JSON response:
[{
"Player": {
"username": "TestPlayer",
"email": "",
"first_name": "",
"last_name": "",
"platform": ""
},
"Score": {
"score": "23",
"created": "2012-07-13 22:06:46",
"difficulty": "0",
"platform": ""
}
}]
Trying to format this JSON into a DIV, with this (which also contains my call):
$(document).ready(function(){
$.post('scoreoid_proxy.php', {action:'curl_request', method:'getScores', response:'JSON'},
function(data) {
$.each(data.Player, function(i,Player){
content = '<p>' + Player.username + '</p>';
content += '<br/>';
$(content).appendTo("#response");
});
});
});
However, I am getting the following error:
object is undefined
length = object.length,
Any help would be appreciated, I’m sure it’s something simple I am missing. Thank you.
datais an array (of objects).EDIT: You need to tell jQuery that this is JSON, and that it needs to parse it. That can be done by adding
'json'as a parameter to$.post(after the callback).