lundi 28 avril 2014

Simple question: Read message from the server

Hi,

I have a simple question. I have a form for registration. I create a model.



Code:



Ext.define('myapp.model.Registration', {
extend: 'Ext.data.Model',
fields: ['username','password', 'retype_password','email','first_name','last_name','phone'],
//default proxy
proxy: {
type: 'rest',
url: 'client_register',
appendId: false,
actionMethods: {
create: 'POST'
},
reader: {
type: 'json',
root: 'results'
},
writer: {
type: 'json'
}
}
});

And in my controller, I register the new user as follows:


Code:



var vals = regForm.getValues();
var new_rec = Ext.create('myapp.model.Registration', vals);
new_rec.save({
success: function (response) {

},
failure: function (response) {

}
});

The server successfully registers the new account and returns basically the same information of the client account in a json object under the "results" entry. However I want to add extra information from the server, for example, status, sessionid....

Code:



{
"status": "success",
"sessionid": "123",
"results": {"username": "...", "password":"...","email":"..." ...}
}

In the success function, I'm able to read the data in the json object under "results" like username, email, phone... but not status, and sessionid. I know that proxy parses whatever under the "root" (results), but how can I read extra data sent by the server, in this case, status and sessionid from the server message? I even tried by making the server put extra data into the json object under "results" but these extra data is not accessible (I guess because of the definition of the fields in the model)

Thank you very much,





Aucun commentaire:

Enregistrer un commentaire