2

更新:

我终于找到了解决这个问题的方法。如果您遇到与我相同的问题,可以尝试访问此链接

想要将Jquery DataTablesCodeIgniter Ignited-Datatables库集成时遇到问题

当我使用默认的 DataTables sServerMethod属性“GET”时,我得到了 json 响应,其中包含来自我的 php.ini 的数据。然而,由于 CodeIgniter 使用 post,我坚持加载服务器数据,尽管该函数返回正确的 json 输出。

在此处输入图像描述

所以我按照本指南sServerMethod更改为“POST”。现在我不再坚持加载服务器数据,但我没有得到我需要的数据。

使用sServerMethod GET 的JSON 响应(获取正确的 json,但卡在加载图像中的服务器数据)

{
"sEcho": 0,
"iTotalRecords": 10,
"iTotalDisplayRecords": 10,
"aaData": [
    [
        "Munauwar",
        "Syed",
        "Mr",
        "6012345678",
        "0000-00-00",
        "basikal"
    ],        
    [
        "Mak",
        "Je Wei",
        "Mr",
        "6012345678",
        "0000-00-00",
        "motor"
    ]
],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

使用sServerMethod POST的JSON 响应

{
"sEcho": 1,
"iTotalRecords": 10,
"iTotalDisplayRecords": 0,
"aaData": [],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

这是我的 JavaScript 代码

$('#table1').dataTable({
        "bProcessing": true,
        "bServerSide": true,            
        "sPaginationType": "bootstrap",
        "sAjaxSource": config.base_url + "contact/popup_contact",
        "sServerMethod": "POST"

    });

我在联系人控制器中的功能

function popup_contact()
{
    $this->datatables
         ->select('first_name,last_name,salutation,number,birthday,group_name')
         ->from('tb_contact')
         ->join('tb_contact_group', 'tb_contact.contact_group_id = tb_contact_group.contact_group_id');          

    echo $this->datatables->generate();             

}
4

3 回答 3

2

如果上面的方法还是不行,那是因为你设置了: $config['csrf_protection'] = true; // 在您的 Codeigniter 配置中

只需在 fnServerData 调用中添加 aoData.push 行:

"fnServerData": function(sSource, aoData, fnCallback) {
            aoData.push({name: '<?php echo $this->security->get_csrf_token_name(); ?>', value: '<?php echo $this->security->get_csrf_hash(); ?>'});
                $.ajax({
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': fnCallback
                });
            }
于 2014-01-10T11:12:02.347 回答
1
$('#smstable').dataTable({
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 20,
//"bPaginate": true,
"bAutoWidth": false,
"iDisplayStart": 0,
"bLengthChange": false,//for sorting 10,20,30,50 ....
"sAjaxSource": "././myadmin/ajaxadmin/dt_sms",
"aaSorting": [[ 1, "desc" ]],
"sPaginationType": "full_numbers",
"aoColumns":[
    {"bSearchable": false,"bSortable": false,"bVisible": false},
    {"bSearchable": true,"bSortable": true},
    {"bSearchable": false,"bSortable": false},
    {"bSearchable": true,"bSortable": true},
    {"bSearchable": false,"bSortable": true},
    {"bSearchable": false,"bSortable": false}
],
"fnServerData": function(sSource, aoData, fnCallback){
    $.ajax(
          {
            'dataType': 'json',
            'type'  : 'POST',
            'url'    : sSource,
            'data'  : aoData,
            'success' : fnCallback
          }
      );//end ajx
    // console.log(fnCallback);
}    

});//end datable

Just check my code and check if you missed something. That code works very fine with me.
于 2013-02-25T11:27:32.677 回答
0

每当您卡在从服务器加载数据时.....这基本上是由列集引起的。只需计算“aoColumns”数组并确保与视图文件中设置的表头完全相同。

它一次又一次地发生在我身上......唯一的解决方案一直是列数组集。

于 2015-10-25T18:30:55.640 回答