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

190
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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