search

Home  >  Q&A  >  body text

The record in the database is deleted, but the delete button remains on the front-end interface

<p>When the delete button is clicked, it successfully deletes the record from the database. However, it is not deleted immediately on the front-end page. The deletion result will not be displayed until the page is reloaded or refreshed. </p> <p>My view:</p> <pre class="brush:php;toolbar:false;">@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("Deletion successful!"); }, error: function (jqXHR) { // Http Status is not 200 }, complete: function (jqXHR, status) { // Whether success or error it enters here } }); }; </script></pre></p>
P粉118698740P粉118698740495 days ago627

reply all(2)I'll reply

  • P粉466909449

    P粉4669094492023-08-30 11:58:27

    Please add window.location.reload() code after alert....

    success: function (data) {
                    if (data.length == 0) // 没有错误
                        alert("删除成功!");
                        **window.location.reload();**
                },

    This code will automatically reload your page upon success

    reply
    0
  • P粉014218124

    P粉0142181242023-08-30 11:51:00

    Actually, you deleted the data from the database, but you didn't refresh the page.

    Alternatively, you use Dipendrasinh Vaghela's answer and refresh the entire page.

    Alternatively, if you have a function that searches and displays in the DOM, you can call it when the deletion is successful. This will "only" update the part showing the data.

    reply
    0
  • Cancelreply