Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda