I'm using JSON to return an array of objects identical to each other in variable names, but differing in values. Rather than call the JSON function five times, is there a way that I can put objects within the JSON object so I can reference them like data.1.name, data.2.name, etc?
Current (terrible) code:
$(document).ready(function(){
var data = 'manliness=' + $("#manliness_level_number").html() + '&type=enemy';
load_opponents();
function load_opponents()
{
$.getJSON('http://arflux-rpg.com/game/index.php/handler/request', data, function(data){
if (data.success == true)
{
$("#enemy_list").append("<div id='" + data.name + "' class='enemy'><img class='enemy_image' src='http://dummyimage.com/100x100/000/fff&text=100x100' /><div class='enemy_manliness'>" + data.manliness + "</div><div class='enemy_richliness_reward'>"+data.richliness_reward+"</div><div class='enemy_manliness_reward'>"+data.manliness_reward+"</div></div>");
}
else
{
alert('Failed to load enemies and users! ' + data.err);
}
});
}
[code cut from here for brevity]