猿问

删除功能无法在php ajax中删除表中的一行

我想通过单击删除按钮来删除一行。


我已经完成了编辑行中的数据。我想删除行中的数据。并且删除操作不起作用。


  db.php

    <script>

$(document).ready(function() {

    $.ajax({

        url: "View_ajax.php",

        type: "POST",

        cache: false,

        success: function(dataResult){

            $('#table').html(dataResult); 

        }

    });

    $(document).on("click", ".delete", function() { 

        var $ele = $(this).parent().parent();

        $.ajax({

            url: "delete_ajax.php",

            type: "POST",

            cache: false,

            data:{

                id: $(this).attr("data-id")

            },

            success: function(dataResult){

                var dataResult = JSON.parse(dataResult);

                if(dataResult.statusCode==200){

                    $ele.fadeOut().remove();

                }

            }

        });

    });

});

</script>




delete_ajax.php

    <?php

        include "php/dbConfig.php";

        $id=$_POST['id'];

        $sql = "DELETE FROM `task` WHERE id=$id";

        if (mysqli_query($conn, $sql)) {

            echo json_encode(array("statusCode"=>200));

        } 

        else {

            echo json_encode(array("statusCode"=>201));

        }

        mysqli_close($conn);

    ?>


view_ajax.php

<td><input type='button' onclick="delete_user('<?php echo $row['id'];?>');"

            data-id="<?=$row['id'];?>"

            data-firstname="<?=$row['firstname'];?>"

            data-lastname="<?=$row['lastname'];?>"

            data-username="<?=$row['username'];?>"

            data-password="<?=$row['password'];?>"

            "></button></td>


by clicking the delete button i want the entire row to be deleted.

删除功能不起作用。请帮助我。


哔哔one
浏览 163回答 2
2回答

一只名叫tom的猫

Js 找不到 css 类的删除,在任何地方添加到元素<element&nbsp;class='delete'&nbsp;>remove&nbsp;</element>

白猪掌柜的

尝试delete在 html 标签中添加类<input&nbsp;class="delete"&nbsp;type='button'&nbsp;...&nbsp;>
随时随地看视频慕课网APP
我要回答