jq 修改swal的标题_如何使用JQuery在SWAL中成功调用函数?

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

解决方案

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

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值