Ajax json data not being loaded into datastore
My datastore works when I have a configuration member of 'data: ...raw json' inside the data store but when I try to load it via ajax it doesn't work.
new Ext.data.Store({
model: "SearchResult",
proxy: {
type: "ajax",
url : "test.php",
extraParams : 'test',
reader: {
type: "json",
}
},
});
Note: test.php gets called according to chrome and echoes out:
{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1开发者_高级运维984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' },{stock: 'Tommy', storePhone: '353535', year: '1984', make: 'Ferrari', trim: 'trim', miles: '12345', storename: 'branch name' }
Any ideas what I am doing wrong?
Note: test.php gets called according to chrome and echoes out:
{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' }
And where are square brackets? For your store's config the response should look like
// 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' }
]
do you encode your data as json in php ? like this echo json_encode($data); It's either that or the model is completely different from the response.
A json format would look like this
{'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',
}
You need a "data" wrapper for your JSON:
{"data":[... your JSON ...],"total":9999999,"success":true}
精彩评论