Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Loading Circle will disappear before request is finish

I have this jQuery code:

var now = new Date(Date.now());
console.log("Show LoadingOverlay "+now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds());
            
$( ".loadingOverlay" ).css("display", "block").animate({"opacity": 0.9});       
$.post("myFile.php", {date: true}, function(response) {    
  var now = new Date(Date.now());
  console.log("My Response "+now.getHours() + ":" + now.getMinutes() + ":" +   now.getSeconds());
});
                    
var now = new Date(Date.now());
console.log("Hide LoadingOverlay "+now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds());
$( ".loadingOverlay" ).animate({"opacity": 0}, 500, function() {$( ".loadingOverlay" ).css("display", "none")});

My problem is, that the loadingOverlay will disappear before the $.post request is finish. Here the console to see that:

Show LoadingOverlay 10:8:16
Hide LoadingOverlay 10:8:16
My Response 10:8:20

It should be:

Show LoadingOverlay 10:8:16
My Response 10:8:16
Hide LoadingOverlay 10:8:20

How can I realize it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hiding the overlay should be done in the call back function of the request. I changed the code a bit so that it can run here on Stackoverflow but the callback is the same.

var now = new Date(Date.now());
console.log("Show LoadingOverlay " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds());

$(".loadingOverlay").css("display", "block").animate({
  "opacity": 0.9
});
$.post("data:text/plain;base64,dGV4dA==", function(response) {
  var now = new Date(Date.now());
  console.log("My Response " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds());

  var now = new Date(Date.now());
  console.log("Hide LoadingOverlay " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds());
  $(".loadingOverlay").animate({
    "opacity": 0
  }, 500, function() {
    $(".loadingOverlay").css("display", "none")
  });
});
.loadingOverlay {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="loadingOverlay">overlay</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda