我正在使用PHP和Sweet Alert进行删除确认。问题在于它在显示Sweet Alert之前就已经删除了。
这是我的HTML(其中使用了PHP)。
<div class="delete"><a onclick="return confirmation()" href="'.URLROOT.'/dashboards/delete_note/'.htmlspecialchars($note->note_id).'/'.$data['table'] .'"><i class="far fa-trash-alt"></i></a></div>
这是我的Sweet Alert
function confirmation() {
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
} else {
swal("Your imaginary file is safe!");
}
});
问题是,它没有显示出Sweet Alert,直接跳转到了URL。我需要做一个表单并防止提交或者做其他的处理吗?