Hello,
I have a button with a click event, and when I click on it, I make an ajax request in a foreach. I would like to open a loading mode to run while the requests are being made, but the modal only opens when they all finish and the event ends.
$(document).ready(function(){
$('#loading').modal();
var contadorEnviados = 0;
var contadorErros = 0;
$('#botao').click(function(event){
event.preventDefault();
$('#loading').modal('open');
var emails = $('#emails').val().split("\n");
emails.forEach(function(email){
if(fazRequisicao(email)){
contadorEnviados++;
}
else{
contadorErros++;
}
atualizaContadores(contadorEnviados,contadorErros);
});
inicializaContador();
$('#loading').modal('close');
});
});
function doRequisition
function fazRequisicao(email){
$.get("teste.php", {email: email}, function(resposta){
return resposta;
});
}