一个删除功能,原来的实现方式(注释部分)有多次的回调,会出现第二个swal窗口不显示,回调函数体不执行的情况。后来的解决方式是使用bootstrap的modal模态框,删除成功后显示模态框,模态框关闭后执行刷新,曲线救国啊。
$('button.btn.btn-danger.btn-sm.delOneType').click(function () {
var dTypeId=$(this).attr('key');
swal({
title:"",
text:"确定删除吗?",
type:"warning",
showCancelButton:"true",
showConfirmButton:"true",
confirmButtonText:"确定",
cancelButtonText:"取消",
animation:"slide-from-top"
}, function(){
$.ajax({
url: url+"/delDefinedTypeBydTypeId", //请求的url地址
dataType: "json", //返回格式为json
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
data: {dTypeId: dTypeId}, //参数值
type: "GET", //请求方式
success: function(data, textStatus) {
if(data.status == 1){
/*swal({
title:"",
text:"删除档案类型成功",
type:"success",
showConfirmButton:"true",
confirmButtonText:"关闭",
animation:"slide-from-top"
}, function() {
window.location.reload();
});*/
$('#delSuccModal').modal({backdrop: 'static', keyboard: false}); //初始化并启动
} else {
swal({
title:"",
text:data.msg,
type:"error",
showConfirmButton:"true",
confirmButtonText:"关闭",
animation:"slide-from-top"
});
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log('请求发生错误:' + textStatus);
}
});
});
});