【发布时间】:2014-04-23 14:31:44
【问题描述】:
下面是文档准备功能
Script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "GetUser.ashx",
"sServerMethod": "POST",
"sAjaxDataProp" : "",
"aoColumnDefs": [ {
"aTargets": [ 0 ],
"mData": "download_link",
"mRender": function ( data, type, full ) {
return '<a href="/UserDetail.aspx?ID='+data+'">Detail</a>';
}
} ],
"aoColumns": [
{ "mData": "LoginId" },
{ "mData": "Name" },
{ "mData": "CreatedDate" }
]
});
以下是来自服务器的响应 (GetUser.ashx)
[
{
"UserId": "1",
"LoginId": "white.smith",
"Activated": "Y",
"Name": "Test Account",
"LastName": "Liu",
"Email": "white.smith@logical.com",
"CreatedDate": "1/21/2014 12:03:00 PM",
"EntityState": "2",
"EntityKey": "System.Data.EntityKey"
},
More Data...
]
下面是应该放数据的html表
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th width="15%">User Detail</th>
<th width="15%">LoginID</th>
<th width="15%">Name</th>
<th width="15%">Created Date</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5" class="dataTables_empty">Loading data from server</td>
</tr>
</tbody>
<tfoot>
<tr>
<th width="15%">User Detail</th>
<th width="15%">LoginID</th>
<th width="15%">Name</th>
<th width="15%">Created Date</th>
</tr>
</tfoot>
</table>
预期结果:
但是我遇到了一个问题:
页面加载时,浏览器出现未捕获的异常:
Cannot read property 'length' of undefined
当我进一步检查时,它来自 jquery.dataTables.js 的第 2037 行
var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json );
我检查了json是否有效,但是“aData”为空,为什么会这样?
【问题讨论】:
-
可以查看调用栈,回溯到网页问题的根源...
-
以下属性不使用逗号分隔。这是一种类型吗?
"Email": "white.smith@logical.com" "CreatedDate": "1/21/2014 12:03:00 PM" "EntityState": "2", "EntityKey": "System.Data.EntityKey" -
@Nilesh 不是类型,只是这个帖子忘记加逗号了,这里加回来了
-
对不起,我的意思是错字不是打字:)
标签: javascript jquery asp.net datatables jquery-datatables