How to call a function inside the success in SWAL

2019-03-06 16:01发布

Second function is not working. It doesn't received the id that being passed from the first function.

Here is my JQuery code.

swal({
    title: "Are you sure?",
    text: "You will not be able to recover this record!",
    type: "warning",
    showCancelButton: true,
    confirmButtonClass: "btn-danger",
    confirmButtonText: "Yes, delete it!",
    cancelButtonText: "No, cancel!",
    closeOnConfirm: false,
    closeOnCancel: false
    },
    function(isConfirm) {
    if (isConfirm) {
      // this.$http.delete();
      window.axios.post(`/delete-sl-gl/${brcode}/${slc}/${slt}/${sle}/${cts}`)
        .then(response => {
        // console.log(response.data.sle)
          if (response.data.success === true) {
            swal('Deleted', response.data.message, 'success'); 
            //console.log(response.data.sle)
            spliceSLE_gl(sle.sle);
          }

        })
        .catch(error =>{
        console.log(error.response)
        });
    } else {
      swal("Cancelled", "Your file is safe :)", "error");
    }

I got an error / ignored in spliceSLE_gl(sle.sle);

1条回答
可以哭但决不认输i
2楼-- · 2019-03-06 16:39

A swal instance is a promise. To add functions based on user action, you have to use the then() method.

Here is the structure of a swal with chained catch() and then() methods.

swal({
    // The swal configuration params
  })

  // To avoid getting a "cancel" if user click the close button
  // or clicks on the overlay (outside the swal)
  // "noop" means "no operation".
  .catch(swal.noop)

  // To handle the confirm/cancel buttons
  .then(function (result) {
    if (result) {
      // Your "confirm" function
    }
    if (!result) {
      // Your "cancel" function
    }
  });
查看更多
登录 后发表回答