PDA

View Full Version : catch error messge in callback



bhomass
30 Jan 2008, 6:41 PM
I need a callback function for my combo store, such that when success is false, it pops up a message.


var OpEnumComboStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'http://localhost:8080/crm/loadList?fieldId=4724'}),
reader: new Ext.data.JsonReader({
root: 'List',
fields: ['name', 'value']
})
});
function OpEnumCombocallback(response, options, success){
if (!success) {
Ext.MessageBox.alert('Sorry, please try again. [Q304]',response.responseText);
}
};
OpEnumComboStore.load({callback:OpEnumCombocallback});

the return JSON string is
{ 'success':'false',

'message':'Entity Class Opportunity for table RecordsViewTopRow is not set in session',

}

the callback does catch success==false, but I don't see the reponse message in either response or options.

where is my mistake?

hendricd
30 Jan 2008, 6:53 PM
Try it with a Boolean response:


{ 'success': false ,(ie not a string)

catacaustic
30 Jan 2008, 7:15 PM
There could be a problem when you try to output 'response.responseText'. This isn't the text in the field that you are looking for, instead it's the entire JSON string that was returned by your call.

I use something like
var result = Ext.util.JSON.decode (response.responseText);
Ext.Msg.alert ("Error", result.message);That might help you a bit.

bhomass
30 Jan 2008, 10:53 PM
well, JSON.decode is not it in this case, because the request is done thru a JSONReader with a record defined. the JSON string is already decoded by the time it is passed into response.

However, I found that this.reader.jsonData does provide the raw JSON string. and I was able to retrieve my error message from there.