-
5 Apr 2012 3:11 AM #1
App specific data when success == false
App specific data when success == false
I'm using Json-Ajax to get data from the server with reader's "success" property to pick-up the execution state.
I set the "success" prop. on the server side to indicate some exception occurred there. Along with "success==false", I send some more info about the error, so this can be displayed to the end-user.
However, when the "success==false", I don't know how to get this additional info. Above is the example (I need to get to "error" part):
Code:{ "success": false, "error": { "id": 71, "code": 3, "message": "Access denied", "action": "Please report this to your admin" } }
-
5 Apr 2012 4:53 AM #2
In the success callback for the ajax request decode the json and check what the sucesss property equals, then show the data as required.
E.g. Extjs3 code
Code:Ext.Ajax.request({url: 'text.json', success: function(response, opts){var obj = Ext.decode(response.responseText); if(obj.success !== true){console.log(obj.error.message);}});}
-
5 Apr 2012 4:55 AM #3
Thanks!
I'm using Ext JS 4 and send request indirectly through the Store object (e.g. load()). Here I provide the callback funtion which later receives the following parameters:
- success
- records (always undefined if success == false)
- operation (??)
I am not sure how to extract the rest of the response JSon if the success == false.
Your answer does not help a lot, as the parameters are completely different.
Thanks once more and regards!
-
5 Apr 2012 5:26 AM #4
I was going to say to extend Ext.data.proxy.Ajax but I don't think it's needed.
http://docs.sencha.com/ext-js/4-0/so...ata-proxy-Ajax
http://docs.sencha.com/ext-js/4-0/so...a-proxy-Server
When success is false the processResponse method on the Ajax proxy does this.
operation.setException(result.message);me.fireEvent('exception', this, response, operation);Therefore is you change the returned ajax to instead having error as the object and have message as the object containing all the error data you can then use the hasException() and getError() of the Ext.data.Operation.
-
10 Apr 2012 7:26 AM #5
Thank you once more damo.
Sorry, but I really don't understand your answer.
-
10 Apr 2012 7:52 AM #6
Ok no worries.
Firstly change the json response to like so:
Now as part of the callback using the getError() method of operation it will return the object containing your error data.PHP Code:{
"success": false,
"message": {
"id": 71,
"code": 3,
"message": "Access denied",
"action": "Please report this to your admin"
}
}
PHP Code:.load({
callback: function(records, operation, success){
if(operation.hasException()){
var errorObj = operation.getError();
}
}
})
-
10 Apr 2012 8:12 AM #7


Reply With Quote