Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX成功后删除表行_Php_Jquery_Ajax - Fatal编程技术网

Php AJAX成功后删除表行

Php AJAX成功后删除表行,php,jquery,ajax,Php,Jquery,Ajax,我有数据库表BuildingMaster,它有三个字段ID、BuildingLocation和Status。我有一个PHP页面,它在HTML表格中显示所有建筑细节,如ID、位置和状态。每行中都有删除超链接 当我点击链接时,相关记录已从数据库中删除。但它仍然显示在HTML表中。当我刷新网页时,它将被删除 Building.PHP <!DOCTYPE html> <html> <head> <script type = "text/javascript" s

我有数据库表BuildingMaster,它有三个字段ID、BuildingLocation和Status。我有一个PHP页面,它在HTML表格中显示所有建筑细节,如ID、位置和状态。每行中都有删除超链接

当我点击链接时,相关记录已从数据库中删除。但它仍然显示在HTML表中。当我刷新网页时,它将被删除

Building.PHP

<!DOCTYPE html>
<html>
<head>
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">

function Remove(ID) {   

    $.ajax({
        type: "POST",
        url: "buildingremove.php",
        data: {ID:ID},
        dataType: "JSON",
        success: function(data) {
             $("#Row"+ID).remove();
             $("#Response").html(data.MSG);
        },
        error: function(err) {
             $("#Response").html(err);
        }
    });

}
</script>
</head>
<body>
<table>
    <tr>
        <th>ID</th>
        <th>Location</th>
        <th>Status</th>
        <th>Action</th>
    </tr>
    <?php
    $sq="Select * from buildingmaster";

    $Table=mysqli_query($CN,$sq);

    while ($Row=mysqli_fetch_array($Table)) {  
        $ID=$Row['ID'];

        echo("<tr id='Row'.$ID.'>");
        echo("<td>".$Row["ID"]."</td>");
        echo("<td>".$Row["BuildingLocation"]."</td>");
        echo("<td>".$Row["Status"]."</td>");

        echo("<td>");
        echo("<a href='#' onclick='Remove($ID)'>Delete</a>");
        echo("</td>");
        echo("</tr>");  
    }
    ?>
</table>
<?php                                   
echo("<div>");
echo("<p id='Response'></p>");
echo("</div>"); 
?>
</body>
</html>

函数删除(ID){
$.ajax({
类型:“POST”,
url:“buildingremove.php”,
数据:{ID:ID},
数据类型:“JSON”,
成功:功能(数据){
$(“#行”+ID).remove();
$(“#Response”).html(data.MSG);
},
错误:函数(err){
$(“#响应”).html(err);
}
});
}
身份证件
地方
地位
行动

ajax正在工作,数据库已更新,但删除操作不起作用,因为代码找不到所需的行。 分配行ID的语法格式不正确

替换此项:

echo("<tr id='Row'.$ID.'>");

echo("您好,您是否尝试过将您的javascript包装到jquery的document ready?@WebCode.ie中?如果记录被删除,这完全不相关。成功删除的记录证明代码实际上已正确绑定,因此不需要在document ready处理程序中。事实上,将其添加到一个处理程序中会使代码为c在这种情况下,很容易使用。@KevinB-我只是浏览我提供的链接中的第一行文本…
在文档“就绪”之前,无法安全地操作页面jQuery为您检测到这种就绪状态。
顺便说一句,您正在引入的可爱的SQL注入。除非您希望在某个时间点删除您的数据库,否则请为此使用准备好的语句。@FunkFortyNiner请仔细阅读。这是错误描述的一部分,也是AJAX PHP端工作正常的证明。但是NDD是通过JQuery
.remove()
进行DOM操作的。可能会发现一个带有单引号/双引号的副本。只需删除一个qoute就足够了。PHP插入双引号字符串。@Nawed Khan谢谢。@drChandrakantSharma不客气。请接受答案,以便其他人也可以学习。
echo("<tr id='Row'.$ID.'>");
echo("<tr id='Row".$ID."'>");
echo("<tr id='Row$ID'>");