Show success alert with sweetalert2

Asked

Viewed 142 times

0

When saving the form to the database I want to show a success message to the user. I am trying to use sweetalert2, but it’s not working. I already have the libraries:

<link rel="stylesheet" href="sweetalert2/dist/sweetalert2.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.js"></script>

In the success of ajax I have this way, but it’s not working:

success: function(result)
{ 
 $('.form4')[0].reset();
 swal('Boa!', 'Gravado com sucesso!', 'success');
}

But I get the following mistake:

sweetalert2.min.js:1 Uncaught Typeerror: Cannot read Property 'constructor' of Undefined

Full function:

function inserir_registo()
{  
    var dadosajax = {
        'Pedido' : $("#Pedido").val(),
        'Assunto' : $("#Assunto").val(),
        'Descricao' : $("#Descricao").val()
    };
    $.ajax({
        url: './requisicaomanutencao12',
        type: 'POST',
        cache: false,
        data: dadosajax,
        error: function(){
          $(".error_message").removeClass('hide');
          swal("Erro!", "Tente novamente. Caso persista o erro, contatar Administrador!", "error");
        },
        success: function(result)
        { 
        $('.form4')[0].reset();
       swal('Boa!', 'Gravado com sucesso!', 'success');
        }
    });
}
  • Welcome. Where did you see this function swal in the documentation? On utilizing and example is being called Swal.fire({ ... }).

1 answer

2


From the version 8.0.0, the function swal() became Swal.fire(), as you can see in this official documentation:

inserir a descrição da imagem aqui

You are using the version 8.11.8.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.