Through for
launch the function with ajax request via post. The function sends data to the server and after processing it should output the value " processed n from m " in the counter.
The data is displayed only after the end of the cycle and only the last result shows me. If you look at the console, then everything goes in a cycle.
How to update the counter after each ajax request?
function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer") { request_type = new ActiveXObject("Microsoft.XMLHTTP"); } else { request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); for(var i=0; i < countEl; i++) { run(data[i], i, countEl); } function run(data, i, countEl) { http.open('post', '/modules/index.php?load', false); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http.send("data="+data+"&counter="+i); if(http.readyState == 4 && http.status == 200) { counter(i, countEl); } } function counter(i, m) { var n = i + 1; console.log('Загружено '+n+' из '+m); document.getElementById("counter").innerHTML = 'Загружено '+n+' из '+m; }