The swal stays that way infinetly I am new to javascript. I am using swal to confirm delete of an order. the order is deleted correctly from the database and when I reload the page, I find the order deleted but the thing is that the page is not reloaded automatically.
echo ($paid == 0) ? "<td><p data-placement='top' data-toggle='tooltip' title='Delete'><a href='#' class='btn btn-danger btn-xs delete-confirm' id='" . $orderId . "'><span class='glyphicon glyphicon-trash'></span></p></td>" : "<td></td>";
<script type="text/javascript">
$('.delete-confirm').on('click', function() {
var orderId = $(this).attr('id');
console.log(orderId);
swal({
title: "Are you sure?",
text: "If you delete this post all associated comments also deleted permanently.",
type: "warning",
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
}, function() {
setTimeout(function() {
$.post("delete.php", {
id: orderId
},
function(data, status) {
swal({
title: "Deleted!",
text: "Your post has been deleted.",
type: "success"
},
function() {
location.reload();
}
);
}
);
}, 50);
});
});
</script>
<script src="js/sweetalert.min.js"></script>
and the delete.php is here
<?php
session_start();
include('config.php');
if(!isset($_SESSION['username'])){
header("location: login.php");
}
$orderId = $_POST['id'];
$qry = "DELETE FROM orders WHERE order_id ='$orderId'";
$result=mysqli_query($connection,$qry);
?>
The order is deleted successfully from the database and the swal is not closed even if i wait infinite time and the page is not getting reloaded. Please help me.