`
<script type="text/javascript">
$(function () {
$('#testTable4').dataTable({
"bRetrieve": true,
"bPaginate": true, //翻页功能
"bLengthChange": true, //改变每页显示数据数量
"bFilter": true, //过滤功能
"bSort": true, //排序功能
"bInfo": true,//页脚信息
"bAutoWidth": true,//自动宽度
"sScrollX":"80%",
"sScrollY":"400px",
"oLanguage": {
"sProcessing": "正在加载中......",
"sLengthMenu": "每页显示 _MENU_ 条记录",
"sZeroRecords": "对不起,查询不到相关数据!",
"sEmptyTable": "表中无数据存在!",
"sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
"sInfoFiltered": "数据表中共为 _MAX_ 条记录",
"sSearch": "搜索",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上一页",
"sNext": "下一页",
"sLast": "末页"
}
},
"aoColumns" : [
{ "mData" : "stuNumber"},
{ "mData" : "stuName"},
{"mData" : "stuNamed"},
{"mData" : "stuSex"},
{"mData" : "stuNation"},
{"mData" : "stuBirth"},
{"mData" : "stuNative"},
{"mData" : "stuRegious"},
{"mData" : "stuPolitical"},
{"mData" : "stuHealth"},
{"mData" : "stuSpecial"},
{"mData" : "stuResidence"},
{"mData" : "stuSchoolRoll"},
{ "mData" : "regiousSeat"},
{ "mData" : "stuID"},
{"mData" : "stuAddress"},
{"mData" : "stuMobile"},
{"mData" : "stuEmail"},
{ "mData" : "stuEntranceWay"},
{"mData" : "stuAlone"},
{ "mData" : "stuMartyr"},
{ "mData" : "stuSingle"},
{"mData" : "stuFarmer"},
{ "mData" : "stuEnteranceDate"},
{ "mData" : "stuClass"}
]
});
})
</script>`
首先,我使用dataTable()创建一个数据表。 然后我用ID = testTable4写一个表。
<table id="testTable4" class=" display table-hover" cellspacing="0" width="80%" bgcolor="#2c5959">
<caption>TEST TABLE</caption>
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>曾用名</th>
<th>性别</th>
<th>民族</th>
<th>出生日期</th>
<th>籍贯</th>
<th>宗教信仰</th>
<th>政治面貌</th>
<th>健康状况</th>
<th>特长</th>
<th>户口性质</th>
<th>学籍状态</th>
<th>户口所在地</th>
<th>身份证号</th>
<th>居住地</th>
<th>电话号码</th>
<th>Email</th>
<th>入学方式</th>
<th>是否留守儿童</th>
<th>是否烈士子女</th>
<th>是否独生子女</th>
<th>是否进城务工子女</th>
<th>入学年月</th>
<th>班级</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
现在我想在此表中添加一些数据,所以这里是代码:
<script type="text/javascript">
function addData() {
$.ajax({
type:"POST", //请求方式
url:"${pageContext.request.contextPath}../src/servlet.GetStuInfoServlet",//请求路径
cache: false,
data:"classNumber=1401",//传参
dataType: 'Json',//返回值类型
success:function(string){
var stuStr = JSON.stringify(string)
var stuObj = JSON.parse(stuStr);
$('#testTable4').dataTable().fnAddData(stuObj);
}
});
}
</script>
以下是回复数据:
{"data":[{"stuSingle":"否","stuSex":"男","stuID":"1000383897","stuEntranceWay":"特效拍照","stuFarmer":"否","stuEnteranceDate"
:"2007","stuPolitical":"思密达","stuNative":"韩国","stuSpecial":"拍照","stuSchoolRoll":"正常","regiousSeat":"
无","stuMobile":"11000111010","stuAddress":"上海市奉贤村","stuRegious":"无","stuBirth":"1988","stuNumber":"12345678"
,"stuAlone":"否","stuClass":"1401","stuEmail":"pengpeng_yu@163.com","stuHealth":"健康","stuName":"权志龙","stuMartyr"
:"否","stuResidence":"城市","stuNamed":"权志龙","stuNation":"韩国"},{"stuSingle":"否","stuSex":"男","stuID":"1000383898"
,"stuEntranceWay":"暂无数据","stuFarmer":"否","stuEnteranceDate":"2010","stuPolitical":"zzzz","stuNative"
:"美国","stuSpecial":"睡觉","stuSchoolRoll":"正常","regiousSeat":"无","stuMobile":"10002020010","stuAddress"
:"海底世界美滋滋","stuRegious":"无","stuBirth":"1900","stuNumber":"87654321","stuAlone":"否","stuClass":"1401"
,"stuEmail":"boomboomzz","stuHealth":"健康","stuName":"海绵宝宝","stuMartyr":"否","stuResidence":"海洋","stuNamed"
:"海绵宝宝","stuNation":"美国"}]}
但是,当我点击按钮尝试向表中添加数据时,它会发出如下警告:DataTables warning: table id=testTable4 - Requested unknown parameter 'stuNumber' for row 1, column 0. For more information about this error, please see http://datatables.net/tn/4
所以现在我感到非常困惑,我不知道问题出在哪里?
任何人的帮助,我真的很感激。