ajax 表格删除,jQuery AJAX删除只捕获第一个表格

我试图做一个AJAX调用的PHP文件,删除数据库中的一行,现在的问题是,它只是删除第一行...我'已经研究了很多,没有任何东西可以工作,所以我决定来这里寻求帮助! (GIF解释它更好,我console.logging的jQuery https://thumb.gyazo.com/thumb/1200/_9f12c592fc900ae5fa7b1247257119fd-gif.gif选择的ID) 这里是代码:

jQuery的AJAXjQuery AJAX删除只捕获第一个表格

// Variable to hold request

var request;

// Bind to the submit event of our form

$(".notif_delete").click(function(event){

// setup some local variables

var $form = $(this).closest("form");

// Serialize the data in the form

var Data = {

'notif_id': $('input[name="notif_id"]').val()

};

// Fire off the request to php file

request = $.ajax({

url: "#notification_control.php",

type: "post",

data: Data

});

// Callback handler that will be called on success

request.done(function (response, textStatus, jqXHR){

// Log a message to the console

console.log("Hooray, it worked delete!");

console.log($('input[name="notif_id"]').val());

});

// Callback handler that will be called on failure

request.fail(function (jqXHR, textStatus, errorThrown){

// Log the error to the console

console.log("The following error occurred deleting:" + errorThrown);

console.log($('input[name=notif_id]').val());

});

});

PHP

if(isset($_POST['notif_id'])) {

$stmt = $conn->prepare("DELETE FROM notifications WHERE notif_id = ?");

$stmt->bind_param("i", $_POST['notif_id']);

$stmt->execute();

$result = $stmt->get_result();

$stmt->close();

}

HTML

>= ''%20.%20%24picture%20.%20'' . ''. $from . '
' . '' . $text . '' . ''?>

2017-07-31

Edvinas

+1

目前尚不清楚你想要达到的目标。你说它只会删除第一行。请更清楚最终目标。 –

+0

你的删除语句有“WHERE notif_id =?”,所以你删除单行,你想要做什么? –

+0

是的,我可能说错了,问题是AJAX只使用第一行,如果我选择ID 1000,它仍然会使用ID 1(我会在第二秒附加一个.gif) https:/ /thumb.gyazo.com/thumb/1200/_9f12c592fc900ae5fa7b1247257119fd-gif.gif –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值