页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试。</title>
<link rel="stylesheet" type="text/css" media="screen" href="/test/css/jquery-ui-1.7.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/test/css/ui.jqgrid.css" />
<script src="/test/js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="/test/js/grid.locale-cn.js" type="text/javascript"></script>
<script src="/test/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'d.php',
datatype: "json",
colNames:['编号','名称'],
colModel:[
{name:'sn',index:'sn'},
{name:'title',index:'title'}
],
rowNum:10,
rowList : [20,30,50],
mtype: "POST",
gridview: true,
pager: '#pager',
caption: "Toolbar Searching....",
jsonReader:{
repeatitems:false,
row: "rows",
page: "page",
total: "total",
records: "records"
}
});
$("#list").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false});
//$("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
});
</script>
</head>
<body>
<table id="list"></table>
<div id="page" ></div>
</body>
</html>
程序:
<?php
$responce->page = 1;
$responce->total = 1;
$responce->records = 1;
$responce->rows[0]['id'] = 1;
$responce->rows[0]['cell'] = array ('20130606','testdate...');
echo json_encode($responce);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试。</title>
<link rel="stylesheet" type="text/css" media="screen" href="/test/css/jquery-ui-1.7.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/test/css/ui.jqgrid.css" />
<script src="/test/js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="/test/js/grid.locale-cn.js" type="text/javascript"></script>
<script src="/test/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'d.php',
datatype: "json",
colNames:['编号','名称'],
colModel:[
{name:'sn',index:'sn'},
{name:'title',index:'title'}
],
rowNum:10,
rowList : [20,30,50],
mtype: "POST",
gridview: true,
pager: '#pager',
caption: "Toolbar Searching....",
jsonReader:{
repeatitems:false,
row: "rows",
page: "page",
total: "total",
records: "records"
}
});
$("#list").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false});
//$("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
});
</script>
</head>
<body>
<table id="list"></table>
<div id="page" ></div>
</body>
</html>
程序:
<?php
$responce->page = 1;
$responce->total = 1;
$responce->records = 1;
$responce->rows[0]['id'] = 1;
$responce->rows[0]['cell'] = array ('20130606','testdate...');
echo json_encode($responce);
?>
$responce["page"] = 1;
$responce["total"] = 1;
$responce["records"] = 1;
$responce["rows"][0]["cell"] = array ("sn"=>"20130606","title"=>"testdate...");
echo json_encode($responce);
用firebug可以看到有json数据返回,但在页面上为什么还是显示不了呢
改为$responce->rows[0] = array ('20130606','testdate...');
就可以了
这个很关键提示,php 的 json_encode 函数只能处理 utf8 编码的数据