I'm new with jQuery and I want to know best practices about it... I did something but I feel that this is not the way to go because it does a bunch on query
Here is my code :
$.ajax({
type: 'GET',
dataType: 'json',
url: 'api/items/' + idfinal,
success: function (data) {
$('#item-all').empty();
$('#builder').addClass('hidden');
if ($('#btnsuc').length === 0) {
$('#page').append('<div class="item-searcher" id="item-searcher"><button class="btn-success" id="btnsuc">Retour</button><div class="item-all" id="item-all"></div></div>');
}
else {
$('#item-searcher').removeClass('hidden');
}
for (var i = 0; i < data.length; i++) {
$('#item-all').append('<div class="item-frame-v" id="myitem'+data[i].id_equipement+'" name="'+myid+'" item="'+data[i].id_equipement+'"><img src="'+data[i].image_equipement+'">'+data[i].nom_equipement + '</div>');
idItemActuel = data[i].id_equipement;
$.ajax({
type: 'GET',
dataType: 'json',
url: 'api/stats/' + idItemActuel,
success: function (statsItem){
for(var x =0; x < statsItem.length; x++){
$('#myitem'+statsItem[x].id_equipement).append(statsItem[x].poids_equipement_stats + ' ' + statsItem[x].nom_stats + '<br/>');
}
}
})
}
},
});
I first take data on a particular type, then I extract data from associative entity with the ID I got.
With more data, my ajax will probably take a lot of time to reach all asked elements... What is the best way to go?