-
3 Nov 2011 11:31 AM #1
Answered: Records: I can't access response object after a failed save method
Answered: Records: I can't access response object after a failed save method
Hi all,
Recently I've posted this question, and I thought I had the answer, but there's a problem. I need to access the response object in the "success" and "failure" callbacks of the "save" method of a record:
Code:myRecord.save({ success: function(record, operation) { var response = operation.response; // OK, here I have the response }, failure: function(record, operation) { var response = operation.response // ERROR. operation doesn't have the response! } })
This is a problem for me, because I need to access additional data from the response I send back from the server:
Code:{success: false, errors: [{error: 'Error1'}, {error: 'Error 2'}], msg: 'There were errors', additionalParameters: [{param1: 'Param 1'}]}
Thanks in advance.
-
Best Answer Posted by mitchellsimoens
Do you have access to the proxy/reader from the callback maybe from the 'this' scope? You can get the data there then.
-
4 Nov 2011 5:23 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
- Answers
- 3107
The save method only accepts a config object of Ext.data.Operation which only has a callback function.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
4 Nov 2011 6:07 AM #3
Hi!
Strange, the callbacks defined in "success" and "failure" are called too. Defining "callback" with my callback still receives an Ext.data.Operation object with no "response" object, which is what I need.
This is what I'm receiving in a failure case (from Chrome's console):
However, if I change the name of the property "callback" and I use "success", in a success case the response IS defined:Code:Ext.Class.newClass
- action: "update"
- callback: function (record, operation, success) {
- error: undefined
- exception: true
- records: Array[1]
- request: Ext.Class.newClass
- running: false
- scope: Ext.Class.newClass
- success: false
- __proto__: Class.registerPreprocessor.prototype
Thanks!Code:Ext.Class.newClass
- action: "update"
- complete: true
- records: Array[1]
- request: Ext.Class.newClass
- response: Object -> This is what I need
- resultSet: Ext.Class.newClass
- running: false
- scope: Ext.Class.newClass
- success: true
- __proto__: Class.registerPreprocessor.prototype
-
4 Nov 2011 6:21 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
- Answers
- 3107
Do you have access to the proxy/reader from the callback maybe from the 'this' scope? You can get the data there then.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
4 Nov 2011 7:04 AM #5
Great! That's the way to find the response. I finally access the response in the following way:
I really think this should be part of the operation object. It's too hidden this way.Code:record.save({ callback: function(record, operation, success) { var response = this.getProxy().reader.jsonData; } });
Thanks a lot for your help!
-
13 Nov 2012 7:20 AM #6
Sorry, but I don't understand how it works for you?
reader.jsonData
contains, in my case, entire data loaded so far to the store, but I need access to response object.
And later on to response.responseText. I handle entire batch of operations, so I actually need that for every operation in a batch, that failed.
How to get reference to response object for each operation, and WHY it is not included by default?!
on success I can assess that in the following way:
batch.operations[0].response.responseText
"response" in undefined in case of failure
EDIT: I have finally found rather ackward way of accessing response object in callback arguments!
operation.request.callback.arguments[2]
EDIT2: the path provided above only works for the last operation in batch.


Reply With Quote