【发布时间】:2015-09-05 01:52:24
【问题描述】:
我正在尝试通过 Jquery DataTable 从数据库中获取数据,它给出的错误为:
“DataTables 警告:表 id=tblBindData - 无法重新初始化 数据表。”
function BindData() {
$("#tblBindData").DataTable({
"processing": true,
"serverSide": true,
"sAjaxSource": "FirstTask.aspx/PopulateDatatable",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({});
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (msg) {
var json = jQuery.parseJSON(msg.d);
fnCallback(json);
$("#tblBindData").show();
},
error: function (xhr, textStatus, error) {
if (typeof console == "object") {
console.log(xhr.status + "," + xhr.responseText + "," + textStatus + "," + error);
}
}
});
}
});
}
【问题讨论】:
-
您是否从服务器得到正确的响应?
-
在当前版本的 DataTables (1.10.4) 中,您可以简单地将 destroy:true 添加到配置中,以确保在重新初始化之前删除任何已经存在的表。参考这个stackoverflow.com/a/26968754/795683