1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
    pret is on a distinguished road

      0  

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

  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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Answers
    3356
    Vote Rating
    751
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
    pret is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Answers
    3356
    Vote Rating
    751
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1
    Vote Rating
    0
    pret is on a distinguished road

      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
    68
    Answers
    1
    Vote Rating
    2
    MaciejZabielski is on a distinguished road

      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.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar