Issue
When pressing the delete button it successfully delete the record from database. But not delete from the frontend it gives result after reloading or refreshing the page.
My view:
@foreach (var item in Model)
{
<a href="#" class="phone_number" onclick="del(this)" data-id="@item.id">
<i class="fas fa-trash-alt"></i>
</a>
}
<script>
function del(x) {
var url = '@Url.Action("deleteRent", "Home")';
var rd = x.dataset.id
debugger
$.ajax({
url: url,
type: 'POST',
data: {
id: rd
},
success: function (data) {
if (data.length == 0) // No errors
alert("Delete success!");
},
error: function (jqXHR) { // Http Status is not 200
},
complete: function (jqXHR, status) { // Whether success or error it enters here
}
});
};
</script>
Solution
Actually you delete from database but you don't refresh your page.
Either, you use answer from Dipendrasinh Vaghela and you refresh the whole page.
Or if you have a function which search and show in DOM, you call it when delete is success. That'll update "only" the part showing datas.
Answered By - pier farrugia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.