Here's the code snippet I'm working with:
function updateCharts() {
for (var i = 0; i < charts.length; i++) {
updateChart(charts[i]);
}
sortQueues();
}
function updateChart(chart) {
$.ajax({
type: "POST",
async: true,
data: '{id: ' + chart.Id + '}',
url: "foo/getData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var parsedResponse = JSON.parse(response.d);
insertChartData(chart, parsedResponse);
},
failure: function (response) {
console.Log(response);
}
});
}
I'm facing an issue where the sortQueues()
function is being run before all charts are updated due to ajax calls. As a result, the charts in the HTML aren't sorted as expected. Can anyone suggest a way to ensure that sortQueues()
is only executed after all instances of insertChartData
have completed, without resorting to synchronous calls?