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

457
Visualizações
Sweet Alert - Llamada Ajax sin botón de confirmación

¿Cómo puede usar sweetalert para hacer una llamada Ajax sin un botón de confirmación pero aún mostrar un gif de carga? Básicamente, quiero que se muestre un gif de carga mientras se ejecuta la llamada Ajax. La solución lista para usar requiere que habilite el botón de confirmación antes de realizar la llamada Ajax.

Lo siguiente obviamente no funciona:

 window.swal({ title: "Checking...", text: "Please wait", imageUrl: "images/ajaxloader.gif", showConfirmButton: false, allowOutsideClick: false }, function () { $.getJSON('myurl').done(function (data) { swal("", "Good job!", "success"); }).fail(function (jqXHR, textStatus, err) { swal("", "An error occurred", "error"); }); });
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

No necesitas hacer nada especial. Simplemente haga su llamada ajax después de mostrar swal, y vuelva a llamar a swal cuando se complete su ajax.

 window.swal({ title: "Checking...", text: "Please wait", imageUrl: "images/ajaxloader.gif", showConfirmButton: false, allowOutsideClick: false }); //using setTimeout to simulate ajax request setTimeout(() => { window.swal({ title: "Finished!", showConfirmButton: false, timer: 1000 }); }, 2000);
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" />

over 4 years ago · Santiago Trujillo Relatório

0

Ejemplo de implementación basado en la muy útil respuesta de Ozan :

Usando vue-sweetalert2, VueJS 2 y Axios, y una animación de carga integrada:

 let self = this; this.$swal.fire({ title: "Processing Request...", text: "Please wait", onBeforeOpen() { self.$swal.showLoading(); //Adds built in loader animation during modal open }, onAfterClose() { self.$swal.hideLoading(); //might not be necessary }, allowOutsideClick: false, //makes modal behave captively allowEscapeKey: false, allowEnterKey: false }); axios .post(`/api/myapi`, {"fake": "fake"}) .then(r => { this.$swal.update({ title: "Finished", html: `Response data: ${r.data}` }); this.$swal.hideLoading(); //Disables loader spinner, enables button }) .catch(err => { this.$swal.update({ title: "FAILED!", text: "Something went wrong - either try again or contact support." }); this.$swal.showValidationMessage(`Request failed: ${err}`); this.$swal.hideLoading(); //Disables loader spinner, enables button })
over 4 years ago · Santiago Trujillo 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