PDA

View Full Version : Datastore Callback



Preston85
2 Jun 2011, 11:52 PM
Hi,

When Submitting a form you can use Success and Failure along with the actual JSON response (that has been converted to an Object) or a Request with the JSON response. But when doing a Store load with the Callback function there is no way to access to response?

This seems strangely inconsistent, have I missed something? I would like to do the same techniques as a Form submit to give accurate Error messages from the PHP pages.

Will this require modification of how the store / store load works or should I be able to do this just using the Callback part of the Store Load?

Thanks.

friend
3 Jun 2011, 5:32 AM
The messageProperty config option lets you specify an attribute in the JSON response which contains a user generated message. If you return success: false and return the message property with your JSON response, you can catch the message via an exception event listener:




var store = new JsonStore({
autoLoad: true,
fields: ['price', 'change', 'company', 'pctChange'],
messageProperty: 'message',
root: 'rows',
url: ...,
listeners: {
exception: function(dataProxy, type, action, options, response, mixedArgs) {
Ext.Msg.alert('Error', response.message);
}
}

Preston85
6 Jun 2011, 2:47 AM
Ah thanks, you pointed me in the right direction, I was looking at Load instead of the actual Store listeners.

I did it slightly different from your example as I processed the json myself instead of using the messageProperty as I want to use more than one field (message, errortype, etc) so I can not only give an accurate error message but also get the application to do something depending on type of error (such as log the user out).

Thanks.

Code added to store:

listeners: {
exception: function(dataProxy, type, action, options, response, mixedArgs) {
checkStoreError(response.responseText);
}
}

checkStoreError just processes the Json into an object, checks for expected fields and displays the message and carried out an appropriate action depending on the errortype.

k.kunkel@ibau.de
23 Nov 2011, 7:26 AM
Hi,

I've got nearly the same issue...
My Problem is while using the online appilcation my session is lost.
Exception listener is not fired in that case and i need to access the response object to give feedback to the user.
I do not know what to do...
PLEASE HELP xD