Call ajax by onclick in SWAL

Asked

Viewed 197 times

0

Hello, I’m trying to get after the user click on a button, open a SWAL containing another button that has an ajax function, however, not even the SWAL opens.

$(document).ready(function(){
var encerrar = $('#encerrar');
  $('input').on('click', function () {
      encerrar();
  })

        swal({
                title: "Tem certeza?",
                text: "Realmente quer encerrar o atendimento?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Sim",
                closeOnConfirm: false
        }, function encerrar()
        {
            $.ajax({
                type: "POST",
                url: "../Back/encerrar.php",
                                success: function(data){
                                }
            }).
            done(function(data) {
                 swal("Canceled!", "Your order was successfully canceled!", "success");
                 $('#orders-history').load(document.URL +  ' #orders-history');
             })
             .error(function(data) {
                 swal("Oops", "We couldn't connect to the server!", "error");
             });
         });
        }

1 answer

1

In the line below, you have specified a name for the function, the function must be anonymous.

}, function encerrar(){

It must be so:

}, function(){
  • The error remains

  • checks in your browser console, if clicking "Yes" appears any error. Post this error here!

  • That’s the point, no SWAL appears! I click on the button (appeared) and nothing happens at all

  • Dude you didn’t call the SWAL, try this: https://jsfiddle.net/n45wvL4d/

  • Nothing even didn’t work on jsfiddle

  • You should only copy the HTML, there is no way to run there because there is no way to run an external library there.

Show 1 more comment

Browser other questions tagged

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