我想在数据表中填充数据库的一些值。我无法确定我错在哪里。
我的json对象是正确的。我已经成功初始化了数据表。我看到了很多解决方案,但没有得到任何更好的解决方案。请帮忙 这是我在服务器控制台中的代码和 json 响应
$(document).ready(function() {
var table = $('#example').dataTable({
"processing" : true,
"serverSide" : true,
"ajax" : {
"dataType" : "json",
"contentType" : "application/json; charset=utf-8",
"type" : "POST",
"url" : "${pageContext.request.contextPath}/getdata",
"data": function (data) {
console.log(data);
for(var i=0;i<data.length;i++)
{
}
},
},
"columns" : [ {
"data" : "first_name"
}, {
"data" : "last_name"
}, {
"data" : "position"
}, {
"data" : "office"
}, {
"data" : "start_date"
}, {
"data" : "salary"
} ]
});
});
@RequestMapping(value = "/getdata", method = RequestMethod.POST)
public String getdatatable(Model model) {
List<Traninfo> list = trdao.getTraninfoTable();
System.out.println("-----Current time of a different time zone using LocalTime-----" + list.size());
JSONArray jsonArray = new JSONArray();
for(int i=0; i<list.size();i++ ) {
JSONObject formDetailsJson = new JSONObject();
formDetailsJson.put("last_name", list.get(i).getRemfname());
formDetailsJson.put("position", list.get(i).getTranno());
formDetailsJson.put("office", list.get(i).getBenecountry());
formDetailsJson.put("salary", list.get(i).getRemamountdest());
formDetailsJson.put("first_name", list.get(i).getBenename());
formDetailsJson.put("start_date", list.get(i).getEntereddatetime());
jsonArray.add(formDetailsJson);
}
// responseDetailsJson.put("data", jsonArray);//Here you can see the data in json format
model.addAttribute("data", jsonArray);
System.out.println("After req responseDetailsJson" +jsonArray.toString());
//return new ModelAndView("datatable", "data", jsonArray);
return "datatable";
}
[{
"last_name": "MD SOBAHAN SHARIF",
"position": "705807",
"office": "BD",
"salary": 37217.25,
"first_name": "CHAINA",
"start_date": "2013-11-02 06:31:00+00"
}, {
"last_name": "ASIM SUTRADHOR",
"position": "941076",
"office": "BD",
"salary": 13000.0,
"first_name": "PRASHADI SUTRADOR",
"start_date": "2014-07-19 05:14:00+01"
}, {
"last_name": "MOKTER",
"position": "702040",
"office": "BD",
"salary": 56520.0,
"first_name": "YASMIN.",
"start_date": "2013-10-26 12:12:00+01"
}, {
"last_name": "MD. HASSAN MOROL",
"position": "731692",
"office": "BD",
"salary": 85002.0,
"first_name": "MD. ABED ALI MOROL",
"start_date": "2013-12-04 11:57:00+00"
}, {
"last_name": "DELOWAR",
"position": "674045",
"office": "BD",
"salary": 55020.6,
"first_name": "MRS. LAKI AKTER",
"start_date": "2013-09-22 04:00:00+01"
}, {
"last_name": "FARUK FARUK",
"position": "764600",
"office": "BD",
"salary": 10089.75,
"first_name": "MD JALAL AHMED CHOWDURY",
"start_date": "2014-01-09 12:35:00+00"
}, {
"last_name": "MASUD RANA",
"position": "674054",
"office": "BD",
"salary": 15214.5,
"first_name": "MASUDA BEGUM.",
"start_date": "2013-09-22 04:09:00+01"
}, {
"last_name": "MD. JAHIDUL ISLAM",
"position": "723460",
"office": "BD",
"salary": 50111.25,
"first_name": "ABDUL JABBAR ALI",
"start_date": "2013-11-23 11:12:00+00"
}, {
"last_name": "MD. ANIS MOLLAH",
"position": "802260",
"office": "BD",
"salary": 26058.5,
"first_name": "SHAHINUR AKTER",
"start_date": "2014-02-16 10:49:00+00"
}]
数据表警告:
<块引用>table id=example - 无效的 JSON 响应。有关此错误的详细信息,请参阅 http://datatables.net/tn/1