我有CRUD表。当我点击删除时,会出现一个确认框,但我想用甜蜜警报
更改此确认框的javascript
function delete_unit(id){
if(confirm('Hapus Data?'))// <== I wanna change it with sweetalert
{
$.ajax({
url : "<?php echo base_url('C_unit/delete')?>/" + id,
type : "POST",
dataType : "JSON",
success : function(data)
{
location.reload();
},
error : function(jqXHR, textStatus, errorThrown)
{
alert('Gagal menghapus data');
}
});
}
}
答案 0 :(得分:0)
您可以尝试使用以下代码吗?此外,详细文档也对此有所帮助 https://sweetalert.js.org/guides/。
function delete_unit(id){
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this data!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
$.ajax({
url : "<?php echo base_url('C_unit/delete')?>/" + id,
type : "POST",
dataType : "JSON",
success : function(data)
{
location.reload();
},
error : function(jqXHR, textStatus, errorThrown)
{
alert('Gagal menghapus data');
}
});
}
});
}
这是一个有效的小提琴 https://jsfiddle.net/s7zd9822/