1
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 modal to run while the requirements are being made, but the modal only opens when they all end 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 does Want
function fazRequisicao(email){
  $.get("teste.php", {email: email}, function(resposta){
      return resposta;
 });
}
Is that loop synchronous? How do you know when
fazRequisicaois over?– Sergio
I’m a bit of a beginner, so I’m sorry about ignoring. What would be a synchronous loop? and I know that it ended when it returns the value there in the function
– Glauco Vaz
And if you instead of using #loading.modal('open') use style display:block, change the result?
– PauloHDSousa
Not paul, it is only applied when the block of the event comes to an end
– Glauco Vaz
You can show the code for this function?
– Sergio
I just edited the post, Rgio
– Glauco Vaz