嘿所有我使用AJAX来自Web服务的以下JSON:
{
"data": [
[
"11/11/2014 3:02:37 PM",
"4/13/2015 8:26:37 AM",
"032650147",
"NULL",
"Web Site Problems",
"NULL",
"New",
"6230.758742407"
],
[
...etc etc....
]
]
}
我正在动态创建HTML表格,如下所示:
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Contact Date Time</th>
<th>Last Update Date Time</th>
<th>Member ID</th>
<th>Operator NTID</th>
<th>Question</th>
<th>Redirect Email Address</th>
<th>Status</th>
<th>Receipt Date</th>
</tr>
</thead>
</table>
我用来显示表中返回数据的Javasscript是:
$.ajax({
type: "POST",
crossDomain: true,
url: "complete.aspx/getMemberEmailsDBData",
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/json");
},
data: {},
dataType: "json",
success: function (data) {
console.log(data.d);
$('#example').DataTable({
data: data.d,
columns: [
{ title: "ContactDateTime" },
{ title: "LastUpdateDateTime" },
{ title: "MemberID" },
{ title: "OperatorNTID" },
{ title: "QuestionArea" },
{ title: "RedirectEmailAddress" },
{ title: "Status" },
{ title: "ReceiptDate" }
]
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest);
}
});
加载页面后,它会不断给我提示警告:
DataTables警告:表格id =示例 - 请求的未知参数&#39; 1&#39; 对于第0行,第1列。有关此错误的详细信息,请参阅 http://datatables.net/tn/4
为了解决这个问题,任何人都会看到我缺少的东西吗?
答案 0 :(得分:1)
使用
data: data.d.data,
当您使用javascript array source时,dataTables 不希望源包装成data : [ ... ]
,而只是数组数组。
您的代码在一个小小的演示中 - &gt;的 http://jsfiddle.net/jusbngww/ 强>