我有来自我的数据库的数据,并且我使用数据表显示它...现在我想要做的是删除一条记录,但不是成功返回它会给出错误。
datatable.on('click','.delete-row',function(){
tr = $(this).closest('tr'),
data = datatable.row(tr).data();
var result = confirm('Are you sure you want to delete this record?')
if(result){
$.ajax({
url:'../ajax/delete_users.php',
dataType:'JSON',
data: {id: data.users_id},
success: function(result){
console.log(result);
},
error: function(status){
console.log(status.responseText);
}
});
}
});
这是我的 delete.php
if (isset($_POST['id'])) {
$id = $_POST['id'];
$data = $users->deleteUsers($id);
echo json_encode($data);
}
查询就是这样..
public function deleteUsers($id)
{
$sql = "DELETE FROM tbl_users WHERE users_id = '$id'";
$update = $this->dbh->prepare($sql);
$update->execute();
return $update->rowCount() ? true : false;
}