Php 按下按钮时Jquery从表中隐藏行

Php 按下按钮时Jquery从表中隐藏行,php,jquery,Php,Jquery,我有下表代码: echo "<table border='1'> <tr> <th>Code</th> <th>Name</th> <th>Price</th> </tr>"; $sql = "SELECT * FROM products where updated_account_I

我有下表代码:

echo "<table border='1'>
        <tr>
            <th>Code</th>
            <th>Name</th>
            <th>Price</th>
        </tr>";

$sql = "SELECT * FROM products where updated_account_ID='$aktiv'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['code'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['price'] . "</td>";
    echo "<td>" . "<button name='code' value='".$row['code'] ."'>Delete</button></td>";

echo "</tr>";
echo”
代码
名称
价格
";
$sql=“从更新的账户ID=“$aktiv”的产品中选择*;
$result=mysql\u查询($sql);
while($row=mysql\u fetch\u数组($result)){
回声“;
回显“$row['code']”;
回显“$row['name']”;
回显“$row['price']”;
“删除”;
回声“;
在按下“删除”按钮后,我想使用jquery隐藏或删除指定的行,这也会从数据库中删除记录。有人会这样做吗? 谢谢!jQUERY:

$(".delete").click(function(){
var product_id = $(this).parents('tr').attr('data-product-id');
$(this).parents('tr').remove();
$.ajax({
    url: "remove-record.php",
    data: product_id,
    type: "post",
    success: function(result){
        alert(result);
    }
});
}))

PHP文件:

echo "<table border='1'>
    <tr>
        <th>Code</th>
        <th>Name</th>
        <th>Price</th>
    </tr>";

$sql = "SELECT * FROM products where updated_account_ID='$aktiv'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<tr data-product-id='".$row['id']."'>";
echo "<td>" . $row['code'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . "<button name='code' value='".$row['code'] ."'>Delete</button
</td>";

echo "</tr>";

你必须用AJAXHH来做,我明白了,你能告诉我怎么做吗?谢谢!代码运行良好!编辑:不幸的是,这不起作用。问题是什么?调试代码失败了吗?没有失败,没有错误,但id什么也不做:要调试代码,请在单击函数中添加console.log(),查看请求是否从ajax发送到remove-record.php,或者在JSFIDLE上添加代码
$product_id = $_POST['data'];
$sql = "DELETE FROM products WHERE id=product_id";
echo json_encode('Record deleted');