【发布时间】:2018-01-31 12:57:21
【问题描述】:
我正在处理数据表。我已经发布了 2 个与我的这个问题 this 和 this 相关的问题。
AJAX 调用:
API.call("getBasicCallAnalysisData.json", 'POST', function(data) {
basicData = data;
createTable(basicData);
}, function(error) {
console.log(error);
}, jsonStr);
这是来自服务器的我的 json 响应:
{"msg":null,"code":null,"status":null,"result":[{"aNumber":"3224193861","bNumber":"3217284244","cellID":"410-01-604-30226","dateTime":"2017-06-24 23:08:09.0","duration":801,"imei":"27512671195807","imsi":"35788979525680","operatorId":1,"mscId":"2","fileId":"1"},{"aNumber":"3224193861","bNumber":"3217280585","cellID":"410-01-738-13433","dateTime":"2017-06-24 06:53:13.0","duration":198,"imei":"46341570864238","imsi":"33270572168878","operatorId":2,"mscId":"4","fileId":"2"}],"draw":1,"limit":1000,"recordsFiltered":13442,"recordsTotal":13442}
HTML 表格:
<table id="table" class="display responsive nowrap" cellspacing="0" width="100%">
<thead style="background-color:#303641;">
<tr>
<th>ANUMBER</th>
<th>BNUMBER</th>
<th>DATETIME</th>
<th>DURATION</th>
<th>IMEI</th>
<th>IMSI</th>
<th>CELLID</th>
<th>OPRID</th>
<th>MSC ID</th>
<th>FILE ID</th>
</tr>
</thead>
</table>
这是我加载数据表的功能,但我面临两个错误:
function createTable(data) {
console.log(data);
$('#table').DataTable({
"processing": true,
"serverSide": true,
"bFilter": false,
"iDisplayLength": configData,
dom: 'Bfrtip',
buttons: ['colvis', 'print', 'csv', 'excel', 'pdf'],
searching: false,
language: {
buttons: {
colvis: 'Show/Hide Columns'
}
},
"aaData": data
});
}
参数data是来自服务器的响应。错误是:
DataTables 警告:table id=table - 请求的未知参数 'aNumber' 表示第 0 行第 0 列。有关此错误的更多信息, 请看http://datatables.net/tn/4
和
无效的 JSON 响应。
任何想法,我如何使用 JSON 响应填充数据表?
【问题讨论】:
-
您的 json 似乎有效,根据json Lint 中的测试...您可以检查变量
data的类型...也许它是一个字符串。试试:console.log( typeof(data) );。它应该返回object。对于另一个错误...我认为您的 HTML 需要进行调查。 -
@LouysPatriceBessette 是的,
console.log( typeof(data) );返回object。接下来是什么 ?如何解决这个问题? -
在“HTML”选项卡中是否有表头
<thead>以及包含列标题 like here 的行? -
您会发布您的 HTML 以及您使用的数据表版本吗?
-
是的,我已经在我的问题中发布了我的 HTML 表格
标签: javascript jquery json datatables