I have a table where each record can be deleted by the user:
<td style='text-align: center;'>
<button class='btn btn-danger btn-xs delete' id=9 data-title='Delete' data-toggle='modal' data-target='#delete' >
<span class='glyphicon glyphicon-trash'></span>
</button>
</td>
The jQuery
/ AJAX
call is:
$('.delete').click(function(e) {
var id = $(this).attr('id');
e.preventDefault();
alert(id);
bootbox.confirm("Are you sure? ", function(r) {
if (r) { // Sent request to delete order with given id
alert('SENT REQUEST');
$.ajax({
type: 'GET',
url: 'delete.php',
data: 'id='+id,
success: function(b) {
if (b) { // Delete row
alert('YES');
// orTable.fnDeleteRow($('tr#' + id)[0]);
} else { // Failed to delete
alert('NO');
noty({
text: "There is a problem deleting this record, try again",
layout: "topCenter",
type: "alert",
timeout: 3
});
}
}
});
document.location.reload();
}
});
});
And the delete.php is
if($_GET['id']) {
$id = $_GET['id'];
$sql_delete = "DELETE FROM debiteuren WHERE id = " . $id;
mysqli_query($link,$sql_delete) or die(mysqli_error($link));
}
Any idea why it isn't working?
I get the alert id and the modal "Are you sure?" and the alert "SEND REQUEST". But after that, the page reload and the record with ID = 9 hasn't been deleted.
Kind regards,,
Arie