2013-11-05 87 views
0

我正在嘗試使用JQGrid和Codeigniter做一個網格,我需要一個JSON響應,所以我可以把它放在我的網格上,但是我得到了一個來自控制器的非常奇怪的響應:HTTP響應中的奇怪字符JQGrid

�������������{"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(); 
} 

任何幫助非常感謝。

回答

0

我發現問題,它是在文件的編碼。這些文件以ANSI編碼,我更改爲UTF 8,問題已解決。