DataTables显示不出来数据
html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Styles/demo_page.css" rel="stylesheet" type="text/css" />
<link href="Styles/demo_table_jui.css" rel="stylesheet" type="text/css" />
<link href="Styles/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#companies").dataTable({
"bServerSide": true,
// "sAjaxSource": "JScript1.js",
"sAjaxSource": "page1.aspx?GetData=true",
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"aoColumns": [
{ "mDataProp": "Name" },
{ "mDataProp": "Address" },
{ "mDataProp": "Town" }
]
});
});
</script>
</head>
<body id="dt_example">
<div id="container">
<div id="demo_jui">
<table id="companies" class="display">
<thead>
<tr>
<th>Company name</th>
<th>Address</th>
<th>Town</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
后台page1.aspx
public void GetData()
{
CompanyEntity com = new CompanyEntity();
com.Name = "ww";
com.Address = "hz";
com.Town = "wg";
List<DataTableEntity> list = new List<DataTableEntity>();
DataTableEntity dtEntity = new DataTableEntity();
dtEntity.sEcho = "0";
dtEntity.iTotalRecords = 2;
dtEntity.iTotalDisplayRecords = 2;
dtEntity.aaData.Add(com);
dtEntity.aaData.Add(com);
list.Add(dtEntity);
string str = JsonConvert.SerializeObject(list);
Response.Write(str);
Response.End();
}
后台Response.Write(str);返回的json数据为:
[{"sEcho":"0","iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[{"Name":"ww","Address":"hz","Town":"wg"},{"Name":"ww","Address":"hz","Town":"wg"}]}]
页面没有提示json格式错误,就是一直没数据
这是什么原因?
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(5)

发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。