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

56
Visualizações
Show Load Spinner when make POST API by JQuery

I want to add load spinner when click on Add And remain visible until the completion of POST then get alert Item has been added successfully.

$('#add').click(function() {
        fetch("url")
        .then(response => response.json())
        .then(result => setTimeout(function(){
            location.reload(alert("Item has been added successfully"));
        },1250))
        .catch(error => console.log('error', error));
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could do it simply by putting your showSpinner() function (created by you to show the spinner) before the fetch commands, and then another function to hide the spinner before the alert.

Something like that:

$('#add').click(function() {
        showSpinner();
        fetch("url")
        .then(response => response.json())
        .then(result => setTimeout(function(){
            hideSpinner();
            location.reload(alert("Item has been added successfully"));
        },1250))
        .catch(error => console.log('error', error));
});
about 4 years ago · Juan Pablo Isaza Relatório

0

To display the spinner, you need to use a gif file for display spinner. In the below code you just need to replace the image src attribute with the actual spinner gif path.

You can try this code :

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#add').click(function() {
    // Show Spinner
    $('<span class="spinner-section"><img src="add gif path here" alt="Please wait..." width="30px" /></span>').insertAfter($(this)); 
    fetch('https://www.w3schools.com/jquery/')
    .then(response => response.json()).then(result => setTimeout(function(){
        // Remove Spinner
        $('.spinner-section').remove();
        location.reload(alert("Item has been added successfully"));
    },1250))
    .catch(error => console.log('error', error));
});
});
</script>
</head>
<body>

<button id="add">Test Button</button>

</body>
</html>
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