我试图通过Jquery DataTable从数据库中获取数据,它会产生错误:
“DataTables警告:table 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);
}
}
});
}
});
}
答案 0 :(得分:1)
您的代码中存在一些错误,
dataType
:json
,则无需使用jQuery.parseJSON(msg.d)
。"contentType": "application/json; charset=utf-8",
,那么您应该在将数据传递给ajax之前对其进行序列化。最好从你的ajax电话中删除contentType
。