1
I created a deletion system with sweetalert, when clicking delete, it does not cancel the deletion. The language used is PHP without OO and PDO. Could you help me?
Follow the code of the Alert and the button:
<script>
$(document).ready(function(){
$('.bt').click(function(){
var th = $(this);
var id = $(this).attr("id");
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
$.ajax({
url: 'phpAction/delete.php',
type: 'POST',
data: {idd:id},
success: function(data){
th.parents('tr').hide();
}
})
if (result.value) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
});
});
});
</script>
<button class="btn btn-sm btn-danger bt" id="<?php echo $dados['idUsuario']; ?>"><i class="fas fa-trash-alt"></i></button>
Tried to use the preconfirm?
– adventistaam
I made an example for you take a look: Look there
– adventistaam
But how would I put this function on a button and select the database ID?
– Bolaxano
can use data-id="" in the button or url
– adventistaam
I managed to solve, just change $.ajax to after the IF.
– Bolaxano