Results 1 to 5 of 5

Thread: Access response from the "save" operation on a Model instance?

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

    Default Answered: Access response from the "save" operation on a Model instance?

    Hi guys,

    Having this:

    Code:
    record.save({
            success:        function(record, operation) {
                   // Here I need to access the response
            },
            failure:          function(record, operation) {
                  // Here I need to access the response too
            }
    });
    How can I access the response returned from the server? I couldn't find anything in the operation object.


    Thanks!

  2. Sorry for the delay, I came back today to this part of my app so now I can try your solution.

    The problem is that I need to access the hole response. Suppose my response to a save action is:

    Code:
    { success: true, msg: 'OK!!', data: {id: 1, nameOfEntity: 'EntityName'}, extraParams: {otherParam: 1234, andAnother: 'Another'}}
    I'd like to access "extraParams" or any other parameter from the response. Is this possible?

    BTW: One use case I have for this need is that I have to access errors thrown from the server because I couldn't find a way to make my forms be aware of the errors the server throws after POSTing or PUTting data for a record from the form. Which is the best way to do this?



    Thanks in advance!

  3. #2
    Sencha User
    Join Date
    May 2011
    Posts
    70
    Answers
    4

    Default

    does this help?
    PHP Code:
                        e.record.save({
                            
    success: function(recordaction){
                                
    this.commit();  //the commit cleans the grid 
                                
    console.logExt.String.format("{0} record: {1}"'Updated'record.getId()));
                            }
                        }); 
    or perhaps a listener on your STORE work for you?
    ...
    PHP Code:
    extend'Ext.data.Store',
        
    listeners: {
            
    write: function(storeoperation){
                var 
    record operation.getRecords()[0],
                
    name Ext.String.capitalize(operation.action),
                
    verb
                        
                if (
    name == 'Destroy') {
                    
    record operation.records[0];
                    
    verb 'Destroyed';
                } else {
                    
    verb name 'd';
                }

                if (
    operation.action != 'create'){
                        
    console.log(Ext.String.format("{0} {1} user: {2}",nameverbrecord.getId()));
                    }
            } 

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

    Default

    Sorry for the delay, I came back today to this part of my app so now I can try your solution.

    The problem is that I need to access the hole response. Suppose my response to a save action is:

    Code:
    { success: true, msg: 'OK!!', data: {id: 1, nameOfEntity: 'EntityName'}, extraParams: {otherParam: 1234, andAnother: 'Another'}}
    I'd like to access "extraParams" or any other parameter from the response. Is this possible?

    BTW: One use case I have for this need is that I have to access errors thrown from the server because I couldn't find a way to make my forms be aware of the errors the server throws after POSTing or PUTting data for a record from the form. Which is the best way to do this?



    Thanks in advance!

  5. #4
    Sencha User
    Join Date
    Sep 2010
    Posts
    58
    Answers
    1

    Default

    Nevermind, I've found it. I was using v4.0.2 and recently I've updated to v4.0.7. It seems that the operation argument now has a "response" attribute holding the response I was looking for:

    Code:
    record.save({
            success:        function(record, operation) {
                  operation.response     // Here it is!        
            }});

    Thanks a lot!

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

    Default

    Oops, I didn't want to mark as the best answer that one. My PC is too laggy and when I clicked it did it on the wrong post.

    Sorry about that. I don't know if there's a way to change this. If there is, I'll be happy to fix it.



    Thanks!

Posting Permissions

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