1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    74
    Answers
    1
    Vote Rating
    0
    cwtuan is an unknown quantity at this point

      0  

    Default Unanswered: How to get server response after call model.save()

    Unanswered: How to get server response after call model.save()


    Hi
    I want to let user know why the request is failed after calling model.save().
    So I let server responses {"success":true,"msg": "XXX"}.
    But it seems that failure function is not able to get response.


    PHP Code:
    record.save({
        
    scopethis,
        
    success: function(recordoperation) {
            
    console.log(operation.response); // I can get server response in success        

        
    },
        
    failure: function(recordoperation) {
            
    console.log(operation.response); // undefined
        
    }
    }); 

    I have seen someone listen on a exception event in proxy to get the response,
    but it's not very graceful. Why does the failure can't get response?

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,895
    Answers
    368
    Vote Rating
    176
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    You can use a callback config in save() like below:

    Code:
    Ext.define('MyModel', {
        extend: 'Ext.data.Model',
        fields: ['name'],
        proxy: {
            type: 'ajax',
            url: 'data/json.json',
            reader: 'json'
        }
    });
    
    
    var model = Ext.create('MyModel');
    
    
    model.save({
        callback: function (records, operation, success) {
            if (!success) {
                console.log(operation.request.proxy.getReader().rawData.msg);
            }
        }
    });
    Example response:
    Code:
    {
        "success": false,
        "msg": "server response"
    }
    Or if you want to handle every server response globally you can do something like:
    Code:
    Ext.Ajax.on('requestcomplete', function (conn, response, options) {
        var resp = Ext.decode(response.responseText);
        if (resp.success === true) {
            cosnole.log('success = true');
        } else {
            console.log(resp.msg);
        }
    });
    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager: sheryl@sencha.com

    C
    heck out all of the 2013 SenchaCon presentations here:
    http://www.sencha.com/blog/senchacon...now-available/

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."