当我在数据存储中有一个'data:... raw json'的配置成员但我尝试通过ajax加载它时,我的数据存储无效。
new Ext.data.Store({
model: "SearchResult",
proxy: {
type: "ajax",
url : "test.php",
extraParams : 'test',
reader: {
type: "json",
}
},
});
注意:test.php根据chrome调用并回显:
{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' }
任何想法我做错了什么?
答案 0 :(得分:2)
注意:test.php根据chrome调用并回响:
{股票: 'Tommy',storePhone:'353535',年份:'1984',制作:'法拉利',修剪: 'trim',miles:'12345',storename:'branch name'},
{stock:'汤米', storePhone:'353535',年份:'1984',制作:'法拉利',修剪:'修剪', 里程:'12345',店铺名称:'分店名'},
{stock:'汤米', storePhone:'353535',年份:'1984',制作:'法拉利',修剪:'修剪', 里程:'12345',店铺名称:'分店名称}}
方括号在哪里?对于商店的配置,响应应该类似于
// Notice the square brackets
[
{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },
{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },
{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' }
]
答案 1 :(得分:1)
你在PHP中将你的数据编码为json吗? 喜欢这个echo json_encode($ data); 它或者模型与响应完全不同。
json格式看起来像这样
{'success':true,'values':[{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' }]}
reader:{
type: 'json',
root: 'values',
}
答案 2 :(得分:1)
您的JSON需要一个“数据”包装器:
{"data":[... your JSON ...],"total":9999999,"success":true}