如何调用 Ajax 从我的数据库中删除记录而不重新加载页面


How to call Ajax to remove a record from my database without reloading the page

我想在单击删除按钮的同时从数据库中删除一些记录。目前我正在使用以下代码:

function removeItem(id) {
    $.ajax({
        url:"removeItem_checkOut.php",  
        type:"GET",
        data:"id="+id,
        success:function(content) {
            window.location.reload(); 
        }
    });
}

removeItem_checkOUt.php我只是在运行删除查询。

它对我来说工作正常,但是此代码的问题在于它会重新加载整个页面。我只想在不重新加载页面的情况下执行此操作。

简单的说法是,上述代码的功能很好,但是如果不重新加载页面,我就无法做到这一点。在页面重新加载之前,它不会为页面消失。
谁能帮我...

从成功回调中删除"window.location.reload((;"行。

此行告诉您的 ajax 调用在成功执行窗口后重新加载窗口。

function removeItem(id) {
    $.ajax({
        url:"removeItem_checkOut.php",  
        type:"GET",
        data:"id="+id,
        success:function(html) {
               $('#div_contains_data').html(html); //put your div id of the content (if it is a table use that table inside a div) 
        }
    });
}

并在您的removeItem_checkOut.php再次打印div 包含的相同数据部分(此处假设 table.so 再次打印 PHP 文件中的表格(。