To coordinate the AJAX function and the progress update view, don't artificially slow down the function calls. For one thing, it will reduce response time, which the user won't like. For another, the progess will be off by one.
Instead, have the AJAX function call a function that updates the progress when the AJAX call completes either successfully or conditionally, depending on what's appropriate.
Lastly, you may need to change the document structure, which will necessitate changing how you get the progress element. Instead, give the progress element an ID and use getElementById
.
var async_done = (function() {
var doneCount = 0;
return function () {
++doneCount;
document.getElementById("Progress").innerHTML = "Cycles: " + doneCount;
};
})();
for (var i = 0; i < 10; i ++) {
async_function(async_done);
}