0

我正在尝试使用 JQGrid 和 Codeigniter 做一个网格,我需要一个 JSON 响应,所以我可以把它放在我的网格上,但是我从控制器得到了一个非常奇怪的响应:

�������������{"page":"1","total":1,"records":6,"rows":[{"cell":["I01-      01","789456123"]},{"cell":["I01-01","113990035"]},{"cell":["I01-01","112680010"]},{"cell":["MA-0329-1","789456123"]},{"cell":["MA-10001","789456123"]},{"cell":["MA-10001","12345"]}]}

正如你所看到的,我得到的是 JSON,但带有所有这些烦人的符号。我已经使用返回了我的输出

$this->output->set_content_type('application/json')->set_output(json_encode($responce));

但问题还在继续。任何人都知道如何摆脱这些符号?下面是我的代码:

看法:

 $(document).ready(function (){
        jQuery("#list").jqGrid({
            url: 'http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Asignados_controller/loadData',
            mtype : "post",             //Ajax request type. It also could be GET
            datatype: "json",            //supported formats XML, JSON or Arrray
            colNames:['Grupo','Expediente'],       //Grid column headings
            colModel:[
                {name:'grupo', index:'grupo', width:150, editable:true, edittype:'text'},
                {name:'expediente', index:'expediente', width:150, editable:true, edittype:'text'}

            ],
            pager: '#pager',
            rowNum:10,
            rowList:[15,30],
            sortname: 'grupo',
            reloadAfterSubmit: true,
            sortorder: 'asc',
            viewrecords: true,
            postData: {numero:"grupo"},
            caption: 'Asignados',

        }).navGrid('#pager',{edit:false,add:false,del:true},
            {//EDITAR

            },
            {//AGREGAR

              },
              {// DELETE

            },  

            {multipleSearch : false}, // enable the advanced searching
            {closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
        );
    });

控制器:

       function loadData()
   {
        $page = isset($_POST['page'])?$_POST['page']:1; 
        $limit = isset($_POST['rows'])?$_POST['rows']:10; 
        $sidx = isset($_POST['sidx'])?$_POST['sidx']:'grupo'; 
        $sord = isset($_POST['sord'])?$_POST['sord']:'';         
        $start = $limit*$page - $limit; 
        $start = ($start<0)?0:$start; 

        $where = ""; 
        $searchField = isset($_POST['searchField']) ? $_POST['searchField'] : false;
        $searchOper = isset($_POST['searchOper']) ? $_POST['searchOper']: false;
        $searchString = isset($_POST['searchString']) ? $_POST['searchString'] : false;

        /**************************/
        function getWhereClause($col, $oper, $val){
                //array to translate the search type
                $ops = array(
                    'eq'=>'=', //equal
                    'ne'=>'<>',//not equal
                    'lt'=>'<', //less than
                    'le'=>'<=',//less than or equal
                    'gt'=>'>', //greater than
                    'ge'=>'>=',//greater than or equal
                    'bw'=>'LIKE', //begins with
                    'bn'=>'NOT LIKE', //doesn't begin with
                    'in'=>'LIKE', //is in
                    'ni'=>'NOT LIKE', //is not in
                    'ew'=>'LIKE', //ends with
                    'en'=>'NOT LIKE', //doesn't end with
                    'cn'=>'LIKE', // contains
                    'nc'=>'NOT LIKE'  //doesn't contain
                );
                if($oper == 'bw' || $oper == 'bn') $val .= '%';
                if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
                if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
                foreach ($ops as $key=>$value){
                    if ($oper==$key) {
                        $ops = $value;
                    }
                }
                $result ="`". $col . "` " . $ops . " '" . $val . "'";
                return $result;
        }

        if ($_POST['_search'] == "true") {
                $where = getWhereClause($searchField,$searchOper,$searchString);
        }
        /**************************/
        if(!$sidx) 
            $sidx =1;
        $count = $this->db->count_all_results('asignado'); 
        if( $count > 0 ) {
            $total_pages = ceil($count/$limit);    
        } else {
            $total_pages = 0;
        }

        if ($page > $total_pages)
            $page=$total_pages;

        $query = $this->Asignados_model->getAllData($start,$limit,$sidx,$sord,$where); 


        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
        $i=0;
        foreach($query as $row) {
            //$responce->rows[$i]['id']=$row->id;
            $responce->rows[$i]['cell']=array($row->grupo,$row->expediente);
            $i++;
        }

       $this->output->set_content_type('application/json')->set_output(json_encode($responce));
   }

模型:

function getAllData($start,$limit,$sidx,$sord,$where){

    $this->db->select('expediente,grupo');
    $this->db->limit($limit);
    if($where != NULL)
         $this->db->where($where,NULL,FALSE);
     $this->db->order_by($sidx,$sord);
     $query = $this->db->get('asignado',$limit,$start);
     return $query->result();
}

非常感谢任何帮助。

4

1 回答 1

0

我发现了问题,它与文件的编码有关。这些文件以 ANSI 编码,我更改为 UTF 8 并解决了问题。

于 2013-11-07T01:34:02.690 回答