I'm getting information from the database and putting it in an array: (more details of the code)
var alunos = {};
var self = 0;
function sortearAluno(){
var dataForm = {'tipo': "listar"};
$.ajax({
type:'post',
data: dataForm,
dataType: 'json',
url: 'alunoDAO.php',
success: function(dados){
var alunos = {};
for(var i=0;dados.length>i;i++){
self++;
alunos['a'+self] = {
idAluno : dados[i].idAluno,
nome: dados[i].nome,
classe : dados[i].classe,
hp : dados[i].hp,
ap : dados[i].ap,
xp : dados[i].xp,
};
}
}
});
}
So far as normal, when I run the code it can create.
Chrome Console:
Butthen,whenItrytogetthevaluesofthekeys,Icannot.I'vetrieditinmanyways,I'vesearchedeverypagethatgoogleshowedme,butIdidnotfindanythingthatworked.
Someofmyattempts:
console.log(alunos.a1)
Displays="undefined"
console.log(alunos[a1].nome)
Displays="Uncaught ReferenceError: a1 is not defined"
Among other things I've tried. So, does anyone know how to solve this or have some better way to do this?