我有一个名为fetch as belllow的页面:
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row){
$sub_array = array();
$sub_array[] = $row["id"];
$sub_array[] = $row["first_name"];
$sub_array[] = $row["last_name"];
$sub_array[] = '<input type="checkbox" name="confirm" id="'.$row["id"].'" class="btn btn-danger btn-xs delete"></input>';
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal"=> $filtered_rows,
"recordsFiltered"=> get_total_all_records(),
"data" => $data
); echo json_encode($output);
并且我在索引页面中有一个调用删除页面的函数:
$(document).on('click', '.delete', function(){
var user_id = $(this).attr("id");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{user_id:user_id},
success:function(data)
{
alert(data);
dataTable.ajax.reload();
}
});
}
else
{
return false;
}
});
,删除页面如下:
if(isset($_POST["user_id"])){
$statement = $connection->prepare(
"DELETE FROM users WHERE id = :id"
);
$result = $statement->execute(
array(
':id' => $_POST["user_id"]
)
);
if(!empty($result))
{
echo 'Data Deleted';
}}
也在数据库中,我有一个包含4列id,first_name,last_name和check_in(布尔值)的表。我要做的就是隐藏我从数据库中显示的数据,即使我重新加载页面后也将其选中。到现在为止,我只能删除它们。或如果我添加此功能:
$(document).ready(function(){
$("#myTable").on('click','.del',function(){
$(this).closest('tr').hide();
});
});
我可以隐藏它们,但是当我重新加载页面后它们又回来了
答案 0 :(得分:0)
@ User10: (1)您在ajax上的js,数据:{user_id:user_id} ..表中的user_id在哪里,因为它只是id (2)最好把dataType:“ json”(在ajax上)