HTTP响应JQGrid中的奇怪字符

时间:2013-11-05 00:34:58

标签: json codeigniter jqgrid

我正在尝试使用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();
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我发现了问题,它是在文件的编码上。文件以ANSI编码,我改为UTF 8,问题得到解决。