初学EXTJS 直接上手sencha architect,做到store这里用本地数据还好,一连后台数据就蒙圈了,怎么做都不显示,卡好几天了,怎么设置这是jsonstore directstore 啊?看了网上的好些例子,可照着做完一样不显示
首先你确保你get.php能正常运行?浏览器直接访问get.php看报错没有,是否正常输出你需要的json字符串。
不行报错就是你php环境配置没配置好。php版本是多少?mysql_select_db在php7以上就废弃了。改mysqli前缀的
php不太会,mysql_select_db("test"); 是不是少了链接对象了?
mysql_select_db("test",$conn);
Ext.define('jsontest.store.MyJsonStore', {
extend: 'Ext.data.Store',
requires: [
'jsontest.model.MyModel',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyJsonStore',
model: 'jsontest.model.MyModel',
proxy: {
type: 'ajax',
url: 'get.php',
reader: {
type: 'json'
}
}
}, cfg)]);
}
});
加粗地方用符合格式的json文件替换后就显示了,可是我想显示的是sql的数据,要怎么做啊?附get.php,网上抄来试的,不灵
<?php
$conn=mysql_connect("localhost","root","123456",'test');
mysql_select_db("test");
$sql="select id,name,password from login";
$result=mysql_query($sql,$conn);
while($row=mysql_fetch_array($result))
{
$arr4[]=$row;
}
echo json_encode($arr4);
?>
用的是sencha architect 4.24
直接访问php文件能得到数据吗
能f12看下浏览器控制台的报错信息吗,还有get.php这个请求的response
在sencha architect 开发环境下打开里头是源代码,我哭,但是在phpstudy的3w目录下运行是有结果的啊
url: 'get.php',
修改
url: '/get.php',
试试