sweetalert使用隨筆

刪除前確認框:ajax

//找到刪除那天記錄的按鈕,觸發點擊事件
$(".del").on('click', function () {
        swal({
            title: "操做確認",
            text: "刪除後,您將沒法恢復此文件!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
            .then((willDelete) => {
                if (willDelete) {
                    $.ajax({
                        url: '/book_del/',
                        type: 'post',
                        //給這個按鈕綁定一個刪除對象的id,經過this.id獲取
                        data: {'book_id': this.id},
                        success:function () {
                            swal("噗!您的虛擬文件已被刪除!", {
                            icon: "success",})}
                            })
                        //刪除成功後刷新一次頁面,顯示刪除結果
                        .then((value => {
                            location.reload(true)
                        }))
                }
                else {
                    swal("刪除未生效!");
                }
            });
    });        
相關文章
相關標籤/搜索