gpt4 book ai didi

javascript - 在dataTable服务器端删除

转载 作者:行者123 更新时间:2023-11-30 17:37:59 24 4
gpt4 key购买 nike

我的用户列表中有这个问题,dataTable 服务器端运行良好,向我显示我拥有的所有用户,我放置了查看个人资料、编辑个人资料和删除个人资料的按钮。 ID 在 href 中并发送到确切的用户 ID。唯一的一个错误是当我尝试删除任何用户时...我必须通过 ID 删除用户的 ajax 什么都不做...请帮帮我。

这是服务器端(只有连接):

$aColumns = array( 'id_user', 'nombre', 'apellido', 'id_tipo');

/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id_user";

/* DB table to use */
$sTable = "USERS";

/* Database connection information */
$gaSql['user'] = "soft_chas";
$gaSql['password'] = "123456";
$gaSql['db'] = "soft_chas";
$gaSql['server'] = "localhost";

js数据表:

$('#userTabla').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
"sAjaxSource": "server_processing.php",
"aoColumns": [
{ "mData": "id_user" },
{ "mData": "nombre" },
{ "mData": "apellido" },
{ "mData": "tipo" },
{
"mData": null,
"sClass": "center",
"sDefaultContent": "",
"fnRender": function (o) {
return '<a href="user_profile.php?id_user=' + o.aData[0] + '" class="btn btn-success"><i class="icon-user icon-white"></i> Ver perfil</a> <a href="user_edit.php?id_user=' + o.aData[0] + '" class="btn btn-info"><i class="icon-edit icon-white"></i> Editar</a> <a id="' + o.aData[0] + '" class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Borrar</a>'
},
"aTargets": [3]
}
],
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ registros por pag"
}
});

通过ID删除用户的JS:

$(document).ready(function()
{
$('table#userTabla td a.btn-danger').click(function(e)
{
if (confirm("<?php $translate->__("Do you really want to delete User's record?"); ?>"))
{
e.returnValue = false;
var id = $(this).attr('id');
var data = 'recordToDelete='+ id;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "include/delete.php",
data: data,
cache: false,

success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
$('table#userTabla tr:odd').css('background',' #FFFFFF');
});

删除代码:

<?php 
include_once("configs.php");
if(isset($_POST["recordToDelete"]) && strlen($_POST["recordToDelete"])>0 && is_numeric($_POST["recordToDelete"])) {
$idToDelete = filter_var($_POST["recordToDelete"], FILTER_SANITIZE_NUMBER_INT);
if($stmt = $conn->prepare("DELETE FROM USERS WHERE id_user = $idToDelete"))
$stmt->bindParam("$idToDelete", $id_user, PDO::PARAM_INT);
$stmt->execute();
}
$conn = null;
?>

页面中的表格:

<table class="table table-striped table-bordered bootstrap-datatable" id="userTabla" serverSide="true" processing="true">
<thead>
<tr>
<th>ID</th>
<th><?php $translate->__('Name'); ?></th>
<th><?php $translate->__('Last Name'); ?></th>
<th><?php $translate->__('Type'); ?></th>
<th><?php $translate->__('Actions'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5" class="dataTables_empty center"><i class="icon-refresh"></i><img src="img/ajax-loaders/ajax-loader-1.gif" title="ajax-loaders">&nbsp;<?php $translate->__('Please wait'); ?> ...</td>
</tr>
</tbody>
</table>

最佳答案

尝试使用这个 ajax js:

$(document).ready(function(){
$(document).delegate('.btn-danger', 'click', function() {
if (confirm("<?php $translate->__("Do you really want to delete User's record?"); ?>"))
{
var id = $(this).attr('id');
var data = 'recordToDelete='+ id;
var parent = $(this).parent().parent();
$.ajax({
type: "POST",
url: "include/delete.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
$('table#userTabla tr:odd').css('background',' #FFFFFF');
});

关于javascript - 在dataTable服务器端删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21647176/

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