PDA

View Full Version : Server response text at store.load



andyts93
24 Apr 2013, 12:11 AM
I have a JSON store that load data from a PHP script. This script call a Web Service and sometimes it get some errors and I need to capture them and show them in my app. In my script I print this line when I get an error:

echo '{"success": false, "msg": "'.$res->state->Description.'"}';
My Store is:

var targheStore = Ext.create('Ext.data.Store', {
model: modelloTarga,
loadMask: true,
proxy: {
type: 'ajax',
url: 'script/request.php?operazione=searchtarga',
reader: {
type: 'json',
root: 'auto',
totalProperty: 'results'
}
}
});

How can I access to msg property and print the error in my app?

girish.arjunagi
24 Apr 2013, 7:52 AM
You can have listener on the proxy object to capture the service exceptions. Below code might help you.


var targheStore = Ext.create('Ext.data.Store', {
model: modelloTarga,
loadMask: true,
proxy: {
type: 'ajax',
url: 'script/request.php?operazione=searchtarga',
reader: {
type: 'json',
root: 'auto',
totalProperty: 'results'
},
listeners : {
exception : function(proxyObj, response, operation, eOpts) {
console.log('failed');
}
}
}
});

worthlutz
19 May 2013, 5:37 AM
I don't see how to do this. The proxy exception does not get called.

EDIT: I figured out the problem with the proxy exception. See comments at end.

If I use the following store call:


store.load({
addRecords: true,
params: {
options: optionsEncoded
},
callback: function (records, operation, success) {
console.log('IN CALLBACK FROM LOADING STORE...');
if (success) {
console.log('GOOD RESULT');
resultsContainer.fireEvent('DisplayResults', resultsContainer, records, me.options);
} else { // success = false
alert("Error from Server: "); // I want to add message here
console.log('** QueryResults store load callback failure **' );
}
}
});


and my return from the server is:


{
"success": false,
"message": "I want to see this message"
}


How do I get that message from the response in my store load callback?

EDIT: I still do not see how to get the message in the store load callback. Is that possible.?

Thanks,
Worth