gpt4 book ai didi

JavaScript 删除不起作用

转载 作者:行者123 更新时间:2023-11-29 21:56:20 26 4
gpt4 key购买 nike

我的删除功能不起作用。

这是我的带有删除按钮的表格。

// retrieve table contents
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

extract($row);

//creating new table row per record
echo "<tr>";
echo "<td class='text-align-center'><input type='checkbox' name='item[]' class='checkboxes' value='{$employeeid}' /></td>";
echo "<td>{$name}</td>";
echo "<td>{$title}</td>";
echo "<td>{$phone}</td>";
echo "<td>{$supplier_name}</td>";
echo "<td>{$created}</td>";
echo "<td>";

// update record
echo "<a href='update_product.php?employeeid={$employeeid}' class='btn btn-info margin-right-1em'>";
echo "<span class='glyphicon glyphicon-edit'></span> Rediger";
echo "</a>";

// delete record
echo "<a delete-employeeid='{$employeeid}' delete-file='delete_product.php' class='btn btn-danger delete-object'>";
echo "<span class='glyphicon glyphicon-remove'></span> Slet";
echo "</a>";

echo "</td>";
echo "</tr>";
}
//end table<br>
echo "</table>";

这是我的删除功能

// delete single record

$(document).on('click', '.delete-object', function(){


// php file used for deletion
var delete_file = $(this).attr('delete-file');

var id = $(this).attr('delete-id');
var q = confirm("Are you sure?");

if (q == true){

$.post(delete_file, {
object_id: id
}, function(data){
location.reload();
}).fail(function() {
alert('Unable to delete.');
});

}
return false;
});

我从一个教程中得到了代码,我修改了很多。
除了删除功能之外,其他一切都正常。

PHP 代码

<?php
// check if value was posted
if($_POST){

// include database and object file
include_once 'config/database.php';

// delete query
$query = "DELETE FROM employeestest WHERE employeeid = ?";
$stmt = $con->prepare($query);
$stmt->bindParam(1, $_POST['object_employeeid']);

if($stmt->execute()){
// redirect to read records page and
// tell the user record was deleted
echo "Medarbejderen er slettet.";
}else{
echo "Medarbejderen kunne ikke slettes.";
}
}
?>

最佳答案

改变

var id = $(this).attr('delete-Id');

var id = $(this).attr('delete-employeeid');

并且,将 $.post 更改为 $.ajax 正如我所给出的

<script>
$(document).on('click', '.delete-object', function(){
var delete_file = $(this).attr('delete-file');
var id = $(this).attr('delete-employeeid');
var q = confirm("Are you sure?");
if (q == true)
{
$.ajax({url:delete-file,cache:false,success:function(result){
alert('Successfully Deleted');
}});
}
return false;
});
</script>

关于JavaScript 删除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33127014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com