Results 1 to 6 of 6

Thread: Records: I can't access response object after a failed save method

  1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
      0  

    Default 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.

  2. Do you have access to the proxy/reader from the callback maybe from the 'this' scope? You can get the data there then.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    The save method only accepts a config object of Ext.data.Operation which only has a callback function.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
      0  

    Default

    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):

    Code:
    Ext.Class.newClass
    1. action: "update"
    2. callback: function (record, operation, success) {
    3. error: undefined
    4. exception: true
    5. records: Array[1]
    6. request: Ext.Class.newClass
    7. running: false
    8. scope: Ext.Class.newClass
    9. success: false
    10. __proto__: Class.registerPreprocessor.prototype
    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
    1. action: "update"
    2. complete: true
    3. records: Array[1]
    4. request: Ext.Class.newClass
    5. response: Object -> This is what I need
    6. resultSet: Ext.Class.newClass
    7. running: false
    8. scope: Ext.Class.newClass
    9. success: true
    10. __proto__: Class.registerPreprocessor.prototype
    Thanks!

  5. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Great! That's the way to find the response. I finally access the response in the following way:

    Code:
    record.save({                
        callback:        function(record, operation, success) {
            var response = this.getProxy().reader.jsonData;
        }
    });
    I really think this should be part of the operation object. It's too hidden this way.



    Thanks a lot for your help!

  7. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    69
    Answers
    1
    Vote Rating
    2
      0  

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •