I have an Ajax request in a for loop, but it seems that the for loop continues looping and the Ajax requests aren't shown until the end of the loop. Here is an example:
for(var i = 1; i < Object.keys(data.masterlist).length; i++) {
var bill = data.masterlist[i];
var bill_info = document.createElement("P");
var bill_info_text = document.createTextNode("Total Price: " + bill.total + " Bill ID: " + bill.bill_id);
bill_info.appendChild(bill_info_text);
result_div.appendChild(document.createElement("br"));
result_div.appendChild(bill_info);
$.ajax({
url: "https://..." + bill.bill_id,
dataType: "json",
success: function(data) {
result_div.appendChild(document.createTextNode(data.bill.customer));
}
});
}
Basically, I have a list of bills and I need to print some basic info about the bill and then make an Ajax request to get more info about the bill, which also needs to be printed.