求助:grid中的store的proxy不能跳转到url:指定的后台(代码附后
extjs吧
全部回复
仅看楼主
level 1
whkgiq 楼主
js代码如下:
Ext.onReady(function(){
var istore=Ext.create('Ext.data.Store',{
autoload:true,
fields:['id','uname','upwd'],
pageSize:5,
proxy:{
type:'ajax',
url:'test.php',
reader:{
type:'json',
totalProperty:'total',
root:'rows'
}
}
});
//Ext.Msg.alert('提示','提示这是一个测试');
Ext.create('Ext.grid.Panel',{
title:'Ext.toolbar.Paging',
renderTo:Ext.getBody(),
width:400,
height:150,
frame:true,
store:istore,
columns:[
{header:'id',width:50,dataIndex:'id',sortable:true},
{header:'用户名',width:100,dataIndex:'uname',sortable:true},
{header:'密 码',width:100,dataIndex:'upwd',sortable:true}
],
bbar:[{
xtype:'pagingtoolbar',
store:istore,
displayInfo:true
}]
});
});
test.php代码如下:
<?php
$limit=5;
$page=1;
$conn = mysqli_connect('localhost', 'root', '', 'books');
mysql_query("SET NAMES UTF8");
$sql = "select count(*) as num from user";
$countres = mysqli_query($conn, $sql);
$countattr = mysqli_fetch_assoc($countres);
$count = $countattr['num'];
if(!isset($_GET['id']))
{
$sql2 = "select id,uname,upwd from user limit ".(($page-1)*$limit).",$limit";
}
else{
$id = $_GET['id'];
$sql2 = "select * from user where id = '$id' limit ".(($page-1)*$limit).",$limit";
}
$rest = mysqli_query($conn, $sql2);
$attr['total'] = $count;
$rds = array();
while ($restattr = mysqli_fetch_row($rest)) {
$rds[] = $restattr;
}
$attr['rows'] = $rds;
//echo json_encode($b);exit;
$jsonstr = json_encode($attr);
echo $jsonstr;
?>
2017年03月03日 08点03分 1
level 1
whkgiq 楼主
后台用的是xampp1,8.1,程序运行后取不到数据,请各位大虾指点
2017年03月03日 08点03分 2
level 1
whkgiq 楼主
我以为是$jsonstr不是标准的json数据,将echo $jsonstr;
改为手动编码:echo '{"total":"4","rows":[["id":"0","uname":"456","upwd":"456"],["id":"1","uname":"123","upwd":"123"],["id":"2","uname":"wwww","upwd":"3343118"],["id":"3","uname":"yyyy","upwd":"75412"]]}'
grid中还是接收不到数据。
2017年03月03日 09点03分 3
level 1
whkgiq 楼主
程序运行后显示为:
2017年03月03日 09点03分 4
level 1
whkgiq 楼主
找到原因了,是操作系统的问题。
2017年03月09日 02点03分 5
我也是这个问题,能请问下具体怎么做的么?
2018年01月02日 22点01分
level 4
初步看是跟后台返回的数据格式有关系
2017年03月27日 02点03分 6
1