After a record is successfully deleted from the table, I would like for the row to turn red, before fading out and not showing in the users view anymore. None of this is happening for me at the moment, with the only action (the effected table row being removed) only being removed upon refreshing the browser.
PHP (file name deletion.php)
if (isset($_POST['ID'])) {
$ID = $_POST['ID'];
if ($conn->query("DELETE FROM user WHERE `ID` = '$ID'") === true) {
$response = array(
'status' => true,
'message' => "Your listing was deleted successfully"
);
} else {
$response = array(
'status' => false,
'message' => $conn->errno
);
}
echo json_encode($response);
}
Javascript
$(document).ready(function () {
// catch click
$('.mlButton').click(function () {
var el = this;
var confirmAlert = confirm("Are you sure? This action can not be undone.");
if (confirmAlert == true) {
// AJAX Request
$.ajax({
url: 'deletion.php',
type: 'POST',
data: {
ID: $(this).val()
},
success: function (response) {
console.log(response);
if (response.status) {
toastr.success(response.message);
el.closest('tr').css('background', 'tomato');
el.closest('tr').fadeOut(800, function () {
$(this).remove();
});
} else {
toastr.error(response.message);
}
}
});
}
});
});
In the console and network response tab, I am getting the correct status and message response, with status = true and message = Your listing was deleted successfully