Reputation: 11
i need help to fix my problem, i got problem after click cancel button on sweetalert its keep success, i want if i click cancel its not success and cancel function, this is my code on a href
<a href="mahasiswa.php?hapus=<?=$tampil[idm]?>" class="btn btn-danger shadow btn-xs sharp delete-link"><i class="fa fa-trash"></i></a>
this is code on javascript
<script type="text/javascript">
jQuery(document).ready(function($){
$('.delete-link').on('click',function(){
var getLink = $(this).attr('href');
swal({
title: 'Apakah kamu yakin? ',
text: "Anda tidak dapat mengembalikan ini!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#4fa7f3',
cancelButtonColor: '#d57171',
confirmButtonText: 'Iya, hapus!',
}).then(function () {
swal(
'Terhapus!',
'Data telah dihapus.',
'success',
window.location.href = getLink
)
});
return false;
});
});
</script>
hope you guys can help me :)
Upvotes: 0
Views: 358
Reputation: 11
I fix my problem
Swal.fire({
title: 'Apakah kamu yakin? ',
text: "Anda tidak dapat mengembalikan ini!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#4fa7f3',
cancelButtonColor: '#d57171',
confirmButtonText: 'Iya, hapus!',
cancelButtonText: 'Batal'
}).then(function (result) {
if (result.isConfirmed) {
Swal.fire(
'Terhapus!',
'Data berhasil terhapus.',
'success',
window.location.href = getLink
)
} else if (
result.dismiss === Swal.DismissReason.cancel
) {
Swal.fire(
'Batal',
'Data tidak terhapus.',
'error'
)
}
});
Upvotes: 1