PDA

View Full Version : How to structure a successful response



pouli
11 Oct 2010, 6:40 AM
Hello to All ( and especially to Condor),

I have a store that the reader is configured from the server with meta-data.
I use an Ext.data.HttpProxy and I have registered the following listeners from the samples:
Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
alert('Before ' + action);
});

Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
alert( action + ':' + res.message);
});

Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
if (type === 'remote') {
alert('REMOTE EXCEPTION (server returned success equals to false) ' + res.message + ' and action ' + action );
}
else if ( type === 'response' ){
alert('The server returned a either 404, 500 or the response meta-data does not match that defined in the DataReader (e.g.: root, idProperty, successProperty).');
}
});


I am receiving the request from the client and I process it normally.
Now I need to tell the client that everything went just fine.

I tried to send back a json message with the meta-data and
{"success":"true"}I tried to send back only the previous message without the meta-data but always the exception listener alerts me about an error.

What should I send back to the server in order to tell hm that everything went fine ?

Thank you in advance

Condor
11 Oct 2010, 7:17 AM
A successful response for what? A read, create, update or delete action or maybe even a form submit?

pouli
11 Oct 2010, 7:21 AM
Sorry Condor,

I haven't thought of specifying this.
I use this
var proxy = new Ext.data.HttpProxy({
api:{
read : '/ajax/remote?doAction=AJAX_loadAdditionalRemark',
update : '/ajax/remote?doAction=AJAX_saveAdditionalRemark'
}
});

and I want to inform the client that my update was successful.

Condor
11 Oct 2010, 7:29 AM
OK, but the fact that the 'load' or 'write' event fires is already an indication that the action was successful.

pouli
11 Oct 2010, 7:52 AM
Condor,

even when I do not return any answer to the client the alert inside the exception listener is fired.
Why this is happening ?

Condor
11 Oct 2010, 8:06 AM
Both 'read' and 'update' expect a certain response.

For both 'read' and 'update' the server needs to return data that can be read by the JsonReader.

pouli
11 Oct 2010, 8:12 AM
For the read it seems that I handle it ok.
If the answer for the read is this:
{"metaData":{"totalProperty":"total","idProperty":"id","root":"remarks","fields":["id","text"],"successProperty"
:"success"},"total":22,"success":"true","remarks":[.... blah..blah.....]}What should I return for the update ?
Where should we define this?

Condor
11 Oct 2010, 9:42 AM
I don't use Ext.Direct myself, so I'm not completely certain, but I know you at least need to return the updated record data (and I don't recommend returning metaData for an update).

pouli
15 Oct 2010, 3:24 AM
I do not think that I use Ext.Direct as well.
I tried to return the same message only or with a success: true and a total attribute but with no success.

The only change is that I receive a different type (response and remote) of exception.

pouli
18 Oct 2010, 4:17 AM
I found the solution.
The server must always return a success: true if this is set for the reader.
Take care not to return the true as a string since this will be taken as a false.

Additionally returning the whole data set of the updated rows is not necessary.

Condor thank you once again.