Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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
Javascript 从数据库中删除记录的按钮_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 从数据库中删除记录的按钮

Javascript 从数据库中删除记录的按钮,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,脚本: HTML/PHP: $('.removeVehicle').click(function() { var $this = $(this), $row = $(this).parent().parent(); alert($row.attr('data-vehicle-id')); if (confirm("Delete vehicle? ") == true) { $.post("removevehicle.php", {Id:

脚本:

HTML/PHP:

$('.removeVehicle').click(function() {
    var $this = $(this),
        $row = $(this).parent().parent();

    alert($row.attr('data-vehicle-id'));

    if (confirm("Delete vehicle? ") == true) {
        $.post("removevehicle.php", {Id: $row.attr('data-vehicle-id')});
    };
});

£
编辑行
保存行
开始销售
removevehicle php:

<?php while ($row = $products->fetch_assoc()) { ?>
    <tr data-vehicle-id="<?= $row['Vehicle_ID']?>">
        <td class="VRM"><?= $row['VRM']; ?></td>
        <td class="Make"><?= $row['Make']; ?></td>
        <td class="Model"><?= $row['Model']; ?></td>
        <td class="Colour"><?= $row['Colour']; ?></td>
        <td class="Mileage"><?= $row['Mileage']; ?></td>
        <td class="Advertised Price">£<?= $row['Advertised_Price']; ?></td>
        <td class="Date of Registration"><?= $row['Date_of_Registration']; ?></td>
        <td class="HPi Status"><?= $row['HPI_Status']; ?></td>
        <td class="actions">
            <button class="editLine">Edit line</button>
            <button class="saveLine hide">Save line</button>
            <button class="startSale" onclick="div_showSale()">Start Sale</button>
            <button class="removeVehicle"><img id="trash" src="images/trash.png" alt="Delete Vehicle" height=20 width=20></button>
        </td>
    </tr>
 <?php } ?>

使用
.data()
获取数据属性信息。同时返回PHP结果并将其转储到
控制台
。最后,检查控制台是否有错误。改用这个:

PHP:

JS:


我认为问题在于sql查询和将车辆id用引号括起来

如果要在这样的回调中删除该行,请执行以下操作:

$('.removeVehicle').click(function() {
    var $this = $(this),
        $row = $(this).parent().parent();

    var vehicle_id = $row.data("vehicle-id");

    if (confirm("Delete vehicle? ") == true) {
        $.post("removevehicle.php", {Id: vehicle_id}, function(result) {
            console.log(result);
        });
    }
});

您是否尝试过删除速记ajax方法并使用完整签名?$,ajax({url:php调用,method:post,等等……有时当$.post不运行时,这对我有效。php代码运行吗?你说它运行到警报,它不运行到post代码吗?
$query = $mysqli->query($queryStr);
echo $query;
$('.removeVehicle').click(function() {
    var $this = $(this),
        $row = $(this).parent().parent();

    var vehicle_id = $row.data("vehicle-id");

    if (confirm("Delete vehicle? ") == true) {
        $.post("removevehicle.php", {Id: vehicle_id}, function(result) {
            console.log(result);
        });
    }
});
$.post("removevehicle.php", {Id: $row.attr('data-vehicle-id')}, function() {
    // delete the row
});