以下是文档就绪函数:
以下是从服务器 (GetUser.ashx) 返回的响应:
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"为null,为什么会这样?
"Email": "white.smith@logical.com" "CreatedDate": "1/21/2014 12:03:00 PM" "EntityState": "2", "EntityKey": "System.Data.EntityKey"
- Nilesh