一個刪除功能,原來的實現方式(注釋部分)有多次的回調,會出現第二個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); } }); }); });