本文介绍了如何使用JQuery在SWAL中成功调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第二个功能不起作用.它没有收到从第一个函数传递来的id.

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

这是我的JQuery代码.

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");
    }

我在 spliceSLE_gl(sle.sle);中出现错误/被忽略了

推荐答案

swal 实例是承诺.要基于用户操作添加功能,必须使用then()方法.

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

以下是带有链式 catch() then()方法.

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
    }
  });

这篇关于如何使用JQuery在SWAL中成功调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 19:32