I create a json object in php and send it back to the main page:
$invSlots = array();
$invSlots['slots'] = array();
for( $i = 1; $i < $player_max_slots+1; $i++){ //player max slots comes from db
$invSlots['slots'][$i] = $inventory_info3[$i];
}
$json = $invSlots;
$encoded = json_encode($json);
die ($encoded);
And the post response is this:
{"slots": {
"1": "1",
"2": "0",
"3": "0",
"4": "4",
"5": "0",
"6": "0",
"7": "3",
"8": "0",
"9": "0",
"10": "0",
"11": "2",
"12": "0"
}
}
Im trying to get the amount of slots like so:
var myResponse = JSON.decode('(' + responseText + ')'); //decode server json response
maxSlots = myResponse.slots.length; //set max slots
but myResponse.slots.length just returns undefined, how can i fix it?