您好,我已经为此工作了将近2个小时。我似乎找不到关于未在jqGrid上显示结果的错误。我尝试回显json_encode并显示。我的jqGrid在本地站点上工作,但不在实时站点上工作。我正在传递参数,以便它不会显示未包含的其他项目。
这是我得到的:
//控制器
function all ($eid)
{
$page = isset($_POST['page'])?$_POST['page']:1;
$limit = isset($_POST['rows'])?$_POST['rows']:10;
$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rank';
$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;
if (isset($_POST['_search']) == 'true') {
$ops = array(
'eq'=>'=',
'ne'=>'<>',
'lt'=>'<',
'le'=>'<=',
'gt'=>'>',
'ge'=>'>=',
'bw'=>'LIKE',
'bn'=>'NOT LIKE',
'in'=>'LIKE',
'ni'=>'NOT LIKE',
'ew'=>'LIKE',
'en'=>'NOT LIKE',
'cn'=>'LIKE',
'nc'=>'NOT LIKE'
);
foreach ($ops as $key=>$value){
if ($searchOper==$key) {
$ops = $value;
}
}
if($searchOper == 'eq' ) $searchString = $searchString;
if($searchOper == 'bw' || $searchOper == 'bn') $searchString .= '%';
if($searchOper == 'ew' || $searchOper == 'en' ) $searchString = '%'.$searchString;
if($searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni') $searchString = '%'.$searchString.'%';
$where = "$searchField $ops '$searchString'";
}
if(!$sidx)
$sidx =1;
//$this->db->where('event_id', $eid);
$count = $this->db->count_all_results('table1');
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$query = $this->Manager_model->getcontentfromtable($start,$limit,$sidx,$sord,$where, $eid);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
foreach($query as $row) {
$responce->rows[$i]['rank']=$row->rank;
$pace = time_to_sec($row->runner_time)/$row->runner_cat;
$pacex = sec_to_time($pace);
$responce->rows[$i]['cell']=array($row->rank,$row->runner_name,$row->runner_cat,$row->runner_bib,$row->runner_time,$pacex);
$i++;
}
echo json_encode($responce);
}
//View
<table id="list" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</div>
<script type="text/javascript">
$(document).ready(function (){
jQuery("#list").jqGrid({
url: '<?php echo MAINSITE_INDEX."manager/all/$eid" ?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Rank','Runner Name','Category','BIB','Time','Pace'], //Grid column headings
colModel :[{
name:'rank'
,index:'rank'
,width:55
},{
name:'runner_name'
,index:'runner_name'
,width:90
,editable:true
},{
name:'runner_cat'
,index:'runner_cat'
,width:80
,align:'right'
,editable:true
},{
name:'runner_bib'
,index:'runner_bib'
,width:80
,align:'rbib'
,editable:true
},{
name:'runner_time'
,index:'runner_time'
,width:80
,align:'right'
,editable:true
},{
name:'pacex'
,index:'pacex'
,width:150
,sortable:false
,editable:false
}],
rowNum:10,
width: 1050,
height: 300,
rowList:[10,20,30],
pager: '#pager',
sortname: 'rank',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List",
viewPagerButtons: true
}).navGrid('#pager',{edit:true,add:false,del:false});
});
</script>
Model:
function getcontentfromtable($start, $limit, $sidx, $sord, $where, $eid){
$this->db->select('*');
$this->db->limit($limit);
$this->db->where('event_id', $eid);
if($where != NULL)
$this->db->where($where,NULL,FALSE);
$this->db->order_by($sidx,$sord);
$query = $this->db->get('table1',$limit,$start);
return $query->result();
}
最佳答案
错误消息是什么...用Google chrome浏览您的页面,然后按F12或右侧的Inspect元素,您会发现错误。请同时发布错误。检查您的js和CSS文件是否正确指向路径。 。
例:-
或使用解析URL