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

184
Vistas
How to preload upload gif when submitting form

I have a web page where I do the verification of the user and then redirect it. I need to add a standby gif to the screen as soon as the user clicks the log in button. But the verification process takes some time until the result is returned from the service. How can I cache and view the gif?

here is my css

.message {
            margin: 0px; 
            padding: 0px;
            position: fixed;
            right: 0px;
            top: 0px;
            width: 100%; 
            height: 100%; 
            background-color: #666666; 
            z-index: 10000;
            opacity: .8; 
            filter: alpha(opacity=70);
            display:none;
            background: url("assets/images/waiting.gif") no-repeat center center;
        }

here is my html code

<form id="signinForm">
            <input id="email" type="text" placeholder="E-mail"/>
            <input id="password" type="password" placeholder="password"/>
            <input id="login" type="submit" value="Login"/>
        </form>
        
        <div id="divLoading" class="message">
            <p style="position: absolute; top: 30%; left: 45%; color: White;">
            </p>
        </div>  

here is my jquery code

<script> 
          $('#login').click(function (ev) {
                $("#divLoading").show();
                ev.preventDefault();                    
                setTimeout(()=>                    
                $.ajax((getUserInfoForSignIn())).then(r=>{
                    $("#divLoading").hide();
                }), 100);                                                   
               return false;
            });         
        </script>

My gif with the updated code comes up when I click the login button. The critical point here was that I called my user authentication function running on the web service inside my ajax call.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

-- use this on layout -

<div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001;
opacity: .8; filter: alpha(opacity=70);display:none">
<p style="position: absolute; top: 30%; left: 45%; color: White;">
    <img src="~/loading.gif" height="150" width="150">
</p>

-- then call by this way -

  $("#divLoading").show();
  $("#divLoading").hide();
about 4 years ago · Juan Pablo Isaza Denunciar

0

The whole thing as a working snippet:

$('#signinForm').submit(function(ev) {
  $("#waiting").show()
  ev.preventDefault();
  setTimeout(()=>
    $.ajax("https://jsonplaceholder.typicode.com/users/1").then(r=>{
      console.log(`${r.name} is now logged in: ${r.username==="Bret"}`);
      $("#waiting").hide();
    }), 2000);
  return false;
});
#waiting {display:none}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="signinForm">
  <input id="email" type="text" placeholder="E-mail" />
  <input id="password" type="password" placeholder="password" />
  <input id="login" type="submit" value="Login" />
</form>
<img id="waiting" src="https://icons8.com/preloaders/preloaders/1485/Gear.gif">

Please note, that the gif is made visible immediately before the AJAX call and it is hidden again in the callback of the $.ajax(...).then().

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