2
How could I make the following code work?
On the Sleep.php page I have 2 seconds waiting only for the test.
I need the next for
run only
after the full execution of the function corrige
.
I tried to use "Promises" but I can’t understand how to use in each element of for
.
$(".start").on('click',function(e){
var anexo = document.getElementsByClassName('anexos');
for (var i = 0; i < anexo.length; ++i) {
/* aqui eu quero que cada execução do FOR
* seja executada somente após o término
* da função "corrige"...
*/
corrige(anexo[i]);
}
});
function corrige(func){
$.ajax({
type: 'POST',
url: 'sleep.php',
dataType: 'json'
});
}
You want to "pause" the loop every iteration, is that it? Explain better what you’re trying to do. What’s going to happen inside the loop?
– bfavaretto
It would not pause... but wait for the "fix" function to be finished and only after that, continue the loop... inside the FOR will the "fix" function, forgot to put there...
– Matheus LP