Call ajax for onclick in SWAL

0

Hello, I'm trying to get the user to click on a button, open a SWAL containing another button that has an ajax function, but neither does SWAL open.

$(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");
             });
         });
        }
    
asked by anonymous 04.09.2017 / 21:31

1 answer

1

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

}, function encerrar(){

It should look like this:

}, function(){
    
04.09.2017 / 21:41