Jquery Can';t获取dataTables以加载带有json数据的表
我使用ajax调用从服务器检索JSON信息:Jquery Can';t获取dataTables以加载带有json数据的表,jquery,json,datatable,Jquery,Json,Datatable,我使用ajax调用从服务器检索JSON信息: console.log('GOT IT'); /* attach a submit handler to the form */ $('#search-form').submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); /* get the action attribute from the <form
console.log('GOT IT');
/* attach a submit handler to the form */
$('#search-form').submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get the action attribute from the <form action=''> element */
var form = $(this),
url = form.attr('action');
var data = $('form#search-form').serialize()
/* Send the data using post with element id name and name2*/
var posting = $.post(url, data, datype = 'json');
/* Alerts the results */
posting.done(function(data) {
$('#results-table').dataTable({
ajax: data
});
});
});
我想我可能必须将
dataSrc
更改为“result”,但这不起作用。我还尝试使用$.jsonParse()和JSON.parse()解析JSON,并将其作为对象(而不是JSON字符串)馈送到数据表中,但都不起作用。尝试下面的解决方案。这只是一个例子
$('#results-table').dataTable({
"bFilter": false,
"bRetrieve": false,
"bSortClasses": false,
"bLengthChange": true,
"bPaginate": true,
"bAutoWidth": true,
"aaSorting": [],
"aaData": data,
pagingType: "full_numbers",
scrollCollapse: false,
"sScrollX": true,
"autoWidth": true,
bAutoWidth: false,
responsive: true,
stateSave: true,
sDom: 'R<"data-table-wrapper"rt><"bottomside"ilp>',
"drawCallback": function(settings) {
},
"aoColumns": [
{
"sTitle": '<input type="checkbox" class="radio_select hathi">',
"mData": null,
"bSortable": false,
"render": function(obj) {
return '<input name="outcomes_chk" id="checkbox_class" type="checkbox" value="' + obj.id + '" class="radio_select madaniyu ">'
}
},
{
"sTitle": "Name",
"mData": null,
"render": function(obj) {
return '<input type="text" data-name="name[]" class="required form-control input-sm font-body-size readonly transparent edit no-border" value="' + obj.name + '" >'
}
}
]
});
$(“#结果表”).dataTable({
“bFilter”:错误,
“bRetrieve”:假,
“bSortClasses”:false,
“bLengthChange”:正确,
“bPaginate”:对,
“bAutoWidth”:没错,
“aaSorting”:[],
“aaData”:数据,
pagingType:“完整编号”,
错:,
“sScrollX”:对,
“自动宽度”:正确,
鲍托维兹:错,
回答:是的,
stateSave:没错,
sDom:'R',
“drawCallback”:函数(设置){
},
“aoColumns”:[
{
“针”:“”,
“mData”:空,
“可移植”:错误,
“渲染”:功能(obj){
返回“”
}
},
{
“针”:“名称”,
“mData”:空,
“渲染”:功能(obj){
返回“”
}
}
]
});
在aoColumns
中放置您的列。我建议您更改以下行
var data = $('form#search-form').serialize()
到
变量名是data,参数名也是data,并且在同一行中缺少分号 您在data
var?尝试使用data.resulttry更改数据中得到响应<代码>$(“#结果表”).dataTable({aaData:data})代码>我不断得到:“Uncaught TypeError:无法读取未定义“@chiragsatapara”的属性“aDataSort”是如果我只是控制台记录数据变量,我会得到一个JSON格式的简单字符串。
var data = $('form#search-form').serialize()
var formdata = $('form#search-form').serialize();
/* Send the data using post with element id name and name2*/
var posting = $.post(url, formdata, datype = 'json');