What is the best way to loop through the results of an ajax call, sending another ajax call, and using the result to draw a table ? I have enormous trouble using Jquery $.ajax within a loop. Even when I set async to false. I never really know when the last bit of data is available. I try to push all of the data to an object containing an array, but then I need to call the table to draw when the array is completely loaded.
var that = this;
jobdata.ajaxCall(function(json) {
$.each(json, function(p, pitem) {
var itemObj = that.getItembyId(pitem.ItemCode);
if (itemObj === undefined)
{
itemObj = new Item(pitem.ItemCode);
}
itemObj.loadItemDetail(function() {
that.itemlist.push(itemObj);
});
});