javascript - 我的分页脚本无法正常工作,卡在 "Processing..."

标签 javascript php codeigniter

我在搜索模块中的脚本中使用了这些代码,我不知道我做错了什么,因为上周它仍然有效。谁能帮我解决这个问题吗?

这些图像显示了 echo 和 print_r 的结果,以跟踪我收到的数据。

这是我的“echo $qString;”显示我的日期选择器的响应 enter image description here

这两张图片显示了搜索结果,但没有显示在网页上 enter image description here enter image description here

这是我的模型和脚本的完整代码。

    function srch_gen048($data){

    $sEcho = intval($data["sEcho"]);
    $iDisplayStart = intval($data["iDisplayStart"]); //start of record
    $iDisplayLength = intval($data["iDisplayLength"]); //display size
    $pageNum = ($iDisplayStart/$iDisplayLength)+1; //page num
    $colSort = $data['iSortCol_0'];
    $dirSort = strtoupper($data['sSortDir_0']);


    $qString = "dbo.SEARCH_gen048 ";
    $qString .= "" . $colSort . ",";
    $qString .= "'" . $dirSort . "',";
    $qString .= "" . $pageNum . ",";
    $qString .= "" . $iDisplayLength . ","; 
    $qString .= "" . $sEcho . ",";
    $qString .= "'" . $data['sfDate'] . "'";

    //echo $qString;

    $this->db->query('set ansi_padding on
        set ARITHABORT on
        set CONCAT_NULL_YIELDS_NULL on
        set QUOTED_IDENTIFIER on
        set ANSI_NULLS on
        set ANSI_WARNINGS on
        set numeric_roundabort off');

    $res = $this->db->query($qString);
    $res = $res->result();

    $iTotalDisplayRecords   = 0;
    $iTotalRecords          = 0;
    if(count($res) > 0)
    {
        $iTotalDisplayRecords = intval($res[0]->TOTAL_ROWS); //used for paging/numbering; same with iTotalRecords except if there will be search filtering
        $iTotalRecords = intval($res[0]->TOTAL_ROWS); //total records unfiltered
    }

//print_r($res);

    $output = array(
        "sEcho" => intval($sEcho),
        "iTotalRecords" => $iTotalRecords,
        "iTotalDisplayRecords" => $iTotalDisplayRecords,
        "aaData" => array()

    );



    if(count($res) > 0)
    {
        foreach($res as $row)
        {


                                $output['aaData'][] = array(
                                        $row->accnum,
                                        $row->accname,
                                        $row->add1,
                                        $row->accdate,
                                        $row->rmcode,
                                        $row->add4,
                                        $row->solcode,

                                        );

        }
    }


//print_r($output)

    return json_encode( $output );

}

这是我的脚本,我认为它工作正常,因为模型和 Controller 是我自上次工作以来编辑过的唯一代码。

<script>



$(document).ready( function () {



    $('#acctable').dataTable({
                                "sPaginationType": "full_numbers",
                                "bAutoWidth": false,
                                "bFilter": false,
                                "bProcessing": true,
                                "bLengthChange": false,
                                "bServerSide": true,
                                "sAjaxSource": "<?php echo site_url() ?>/welcome/get_gen048",
                                "sServerMethod": "GET",
                                "fnServerData": function (sSource, aoData, fnCallback ) {
                                    aoData.push( { "name": "sfDate" , "value": "<?php echo $_POST["sfDate"] ?>" } );
                                        $.getJSON( sSource, aoData, function (json) {

                                        fnCallback(json);


                                    } );
                                },
                                "aoColumns": [
                                              { "sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false },
                                              { "sClass": "rightAligned"    , "bSortable" : true, "bAutoWidth": false }

                                              ]   

                            }); // oTable   

} );

</script>

最佳答案

无需将output数组转换为json_encode格式。

尝试更改 Controller 中的一些修改

    foreach($res as $row)
    {
            $data['accnum']=$row->accnum;
            $data['accname']=$row->accname;
            $data['add1']=$row->add1;
            $data['accdate']=$row->accdate;

          $output['aaData'][] = $data;
    }


return $output;

并在您的 View 脚本中像这样更改。

mData 属性可用于从任何 JSON 数据源属性读取数据

    "aoColumns": [
   { "mData": "accnum","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
    { "mData": "accname","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
etc..

谢谢!

关于javascript - 我的分页脚本无法正常工作,卡在 "Processing...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35547256/

相关文章:

javascript - 解析云函数失败,出现错误 141

php - 没有 .htaccess 的 Mod 重写

javascript - 从 jquery ajax 调用返回多个值到 php

php - 将列添加到 WooCommerce 中的管理订单列表

javascript - javascript 中的模式弹出窗口

sql - Postgres 进程的高 CPU 使用率

css - CodeIgniter Bootstrap 形式水平模式不工作

javascript - addEventListener 被忽略

javascript - 谷歌地点搜索位置偏差

javascript - 从 session 数组中删除项目 Jquery Ajax