我试图做一个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
>= '' . ''. $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 –