PDA

View Full Version : display JSON response Message text in Message box



bryanevil
11 Jul 2010, 6:03 PM
Hi all

How to display my response message from my JSON response?

Below is my JSON response copy from firebug. In the exception code, this is the value of the responseText property in the res object.


"{\"Data\":null,\"ResponseMessage\":\"Create - Company Fail. \",\"TotalCount\":0,\"success\":false}"



This is my exception handling code, but is not working:


// Listen to "exception" event fired by all proxies
Ext.data.DataProxy.on('exception', function (companyinfoProxy, type, action, options, res) {
//if (type == 'remote') {
Ext.Msg.show({
title: 'REMOTE EXCEPTION',
msg: Ext.decode(res.responseText).ResponseMessage,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
//}
});


Bryan

Elijah
11 Jul 2010, 8:32 PM
I believe that the on exception will only fire in the event say the server fails to execute something or find the file. If you are able to call the page and it is returning data that you have specified it is not an exception nor a fail. It is a successful call. So in your success block you would check the status of 'success' and if it were false then you could display the value of the ResponseMessage.

Condor
11 Jul 2010, 9:44 PM
Correct. an exception event is only fired if the status of the response is not 200. A response with status 200 and success:false is still a successful response for a proxy (but a failure for a form submit).