Talk, guys, cool? I have a annoying problem, and since I had never used AJAX in my life I think the problem is me :( Basically it's like this, I have a GET that returns me the following JSON:
{
"result": 1,
"content": [
{
"PessoaId": "2",
"PessoaNome": "Otavio",
"PessoaTimeId": "1",
"PessoaCategoriaId": "0",
"Treinos": [
{
"TreinoId": "2",
"TreinoNome": "Resistencia",
"TreinoData": "2015-10-19",
"TreinoHorario": "15:44:00",
}
]
}
],
}
Okay, so I have my web page that wants to list people. Everything is quiet there, listing, editing, deleting, etc. But I want to have the option to click on an icon and open a modal with the TRAINS of that person in question. The problem is there, I did something but it did not work out. Here is the code:
function getTreinos(AvaliacaoId){
var url = '../getters/getAvaliacaoById.php?TimeId='+TimeId+'&AvaliacaoId='+AvaliacaoId;
var data = "";
$.get(url, function(response){
serverResponse = response;
console.log(response.content.Treinos);
if(response.result == 1){
for(i in response.content.Treinos){
console.log(response.content.Treinos);
data +='\
<tr>\
<td> </td>\
<td>'+response.content[i].Treinos.TreinoNome+'</td>\
<td></td>\
<td>'+response.content[i].Treinos.TreinoData+'</td>\
<td>'+response.content[i].Treinos.TreinoHorario+'</td>\
<td>'+response.content[i].Treinos.TreinoFinalizado+'</td>\
<td></td>\
</tr>';
}
$('.treino-body').append(data);
var width = new Array();
$(".treino-body tr:eq(0)").find('td').each(function (position){
width[position] = $(this).outerWidth();
});
$(".treino-header tr").find('th').each(function (position){
$(this).css("width", width[position]+5);
});
callModalNovo();
}
else
alert(response.exception);
});
}
It, when it opens the modal, gives me the attributes are undefined. I searched around and it looks like it's something with AJAX synchronization. Does anyone have any other logic to do this? Thankful