PDA

View Full Version : Ajax proxy, what is the expected result?



Toemat
27 Apr 2012, 12:57 PM
Hey guys,
I'm having trouble figuring out what Ext expects the response to be when it does an operation with the Ajax proxy type.

I have a store that has a model that has a proxy, here is my model:


Ext.define('ST.model.usermanager.User', {
extend: 'Ext.data.Model',
fields: ['user_id', 'username', 'first_name' , 'last_name'],
proxy: {
type: 'ajax',
url: 'data/users.php',
reader: {
type: 'json',
root: 'users',
},
},
});


When I add a new record to the store, ajax sends a POST request to users.php. I want the response from that to fill the user_id field in the store, but I don't know how to send that back. Currently I'm sending back { success: true } as the response.

Is there a way to fill the user_id from the response? Thank you!

ramana_l_v
27 Apr 2012, 1:26 PM
As per your code root is mentioned to users you might need to return something like this



{
"success":true,
"users":{
"user_id":316,
"username":"TestUser",
"first_name":"Josh",
"last_name":"Berg"
}
}


and in your reader you can mention successProperty: 'success'