甜蜜的警报,确认无法在PHP应用程序上删除

问题描述

在我的PHP应用程序中,单击链接/按钮后通常会删除

但是当我实现甜蜜警报时,它不起作用或返回false。我正在使用sweetalert2

这是我的按钮代码

<a href="http://localhost/app/pages-role-list.PHP?delete_role=18" class="btn btn-sm btn-danger delete-confirm">delete</a>

我的甜蜜初始化

$('.delete-confirm').on('click',function (event) {
    event.preventDefault();
    const url = $(this).attr('href');


    Swal.fire({
        title: 'Are you sure?',text: "You won't be able to revert this!",icon: 'question',showCancelButton: true,confirmButtonText: 'Delete'

    },function(isConfirm){
        if (isConfirm) {
            return true;
            window.location.href = url;
        }else{
            return false;
        }
    })
});

解决方法

回调未使用正确的语法。

这是工作代码:

$('.delete-confirm').on('click',function (event) {
            event.preventDefault();
            const url = $(this).attr('href');

            Swal.fire({
                title: 'Are you sure?',text: "You won't be able to revert this!",icon: 'question',showCancelButton: true,confirmButtonText: 'Delete'
                
            }).then((result) => {
                if (result.value) {
                    window.location.href = url;
                } else if (result.dismiss === Swal.DismissReason.cancel) {
                    event.preventDefault();
                }
            })
        });

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...