Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Can';t获取dataTables以加载带有json数据的表_Jquery_Json_Datatable - Fatal编程技术网

Jquery Can';t获取dataTables以加载带有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

我使用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 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');