【发布时间】:2020-05-05 22:57:15
【问题描述】:
我已经检查了与此相关的每一个问题,但似乎没有任何效果。这是我的情况:
我使用的是 1.10.20 DataTable 版本,我尝试使用 Ajax jquery($.ajax) 在服务器端插入/删除后刷新数据,然后我尝试刷新 Datatable obj,但没有成功。
我的代码:
function displaymensajes()
{
$.ajax({
async: true,
url: 'ajaxscripts.php',
type: 'POST',
data: ({ "WTDo" : 'displaymensajes', "userid" : <?php echo $_SESSION["IDInversionista"] ?>}) ,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success: function (response) {
$('#tbodymensajes').html(response);
//If I make the call here($("#mensajesTable").DataTable();) instead of on document ready, the Second time the functions is called(I have to call it again when I insert or delete records) I get the error when it can't initialize twice and stuff.
//I try do the ajax.reload() no luck, its gives me the error where Json is not properly formatted(of course I not using Json format in the server side, the response is pure HTML code)
//I try delete the table and create it again, no luck
},
error: function () {
alert("error");
}
});
}
displaymensajes();
//On Document ready... Initialize the API
$(document).ready(function() {
$("#mensajesTable").DataTable();
} );
结果:
Table 中有 2 行,但 Datatable 仍然认为只有 1 行。只有在我刷新页面时才会赶上。帮助?。
PD:有人可以对此 API 进行 refresh() 或 update() 吗?
【问题讨论】:
-
问题是您要替换 tbody 而不是整个表 - 您可以返回整个表(如果您不想使用 .destroy)
-
我可以试试看效果如何
-
是的!!!!是的!!!!!!....天啊...它有效,谢谢!!!.. 不在一百万年后我会考虑这个!感谢您的帮助!!!