PDA

View Full Version : Ext.Model can't get data from remote server



xuronghua
20 Aug 2011, 2:32 AM
this is my code:



Ext.regModel('UserTask', {
fields: ['ret_code', 'ret_desc'],
proxy:{
type:'ajax',
url: 'http://localhost/api.php',
reader: 'json'
},

});

var user3=Ext.ModelMgr.getModel('UserTask');
user3.load(null, {
success: function(record, operation) {
console.log(record);
console.log(operation);
}
});


remote server response text is :
{"ret_code":"SUCC","ret_desc":"","task":"abc"}


the result return is :
record is undefined

steve1964
20 Aug 2011, 8:59 AM
I dont see any store in your code, you need a model and store, you are mixing model and store param in your model definition...

xuronghua
20 Aug 2011, 7:18 PM
thanks your reply

store is multiple Model.
i just want to load one record to Model, not a store

i read the docs api (http://dev.sencha.com/deploy/touch/docs/), the example code in "Using Proxy" can resolve my question, but do not work.

xuronghua
20 Aug 2011, 7:20 PM
this is the docs api:

http://dev.sencha.com/deploy/touch/docs/output/Ext.data.Model.html

jratcliff
22 Aug 2011, 5:05 AM
The issue is with your server's response. When you load data into a store the data needs to be an Array of whatever you are loading. So if you are loading in Json, you need an array of json objects. So just wrap your response in square brackets and then your code will work.