我正在使用响应代码获得JSON完美:200好,但数据未在表中呈现,它们可能在绑定中存在一些问题,请参阅以下内容:
来自FireBug:
发表
Parametersapplication/x-www-form-urlencoded
bRegex false
bRegex_0 false
bRegex_1 false
bSearchable_0 true
bSearchable_1 true
bSortable_0 true
bSortable_1 true
iColumns 2
iDisplayLength 10
iDisplayStart 0
iSortCol_0 0
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
sColumns
sEcho 1
sSearch
sSearch_0
sSearch_1
sSortDir_0 asc
响应:
{"sEcho": 1,"iTotalRecords": 2,"iTotalDisplayRecords": 2,"aaData": [{"name": "Sandeep1","mark": "201"},{"name": "Sandeep2","mark": "202"}]}
JSON:
sEcho 1
iTotalRecords 2
iTotalDisplayRecords 2
aaData [Object { name="Sandeep1", mark="201"}, Object { name="Sandeep2", mark="202"}]
0 Object { name="Sandeep1", mark="201"}
1 Object { name="Sandeep2", mark="202"}
JSP视图:
<div class='table-container'>
<table cellpadding='0' cellspacing='0' border='0' class='display jqueryDataTable'>
<thead>
<tr>
<th>Name</th>
<th>Mark</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.jqueryDataTable').dataTable( {
'bProcessing': true,
"bServerSide": true,
'sAjaxSource': '<jsp:expression>contextPath</jsp:expression>/ajaxDatatable1',
'bJQueryUI': true,
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
debugger;
alert("data in fnServerData : "+ aoData);
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
},
'aoColumns': [
{ 'mData': 'name'},
{ 'mData': 'mark'}
]
} );
} );
</script>
Javascript错误:
DataTables warning (table id = 'DataTables_Table_0'): Requested unknown parameter '0' from the data source for row 0
请指出我正确的方向。感谢
答案 0 :(得分:1)
aaData是您传递的对象数组。
aoColumns定义哪个列应该接收数据。
mDataProp指示数据的处理方式(如果给它一个字符串,它会将数据视为String)
的更多信息