Anderson SA
Anderson SA

Reputation: 25

How to call a function inside a success function in Sencha Touch?

I have a Controller with these functions:

onBtnBack: function(){
    Ext.Viewport.setActiveItem('vLogin');
},

onBtnSave: function (){
 Ext.Ajax.request({
     success: function(response) {
         Ext.Msg.alert('', 'OK', Ext.emptyFn);
         onBtnBack();
     }
 });

},

I'm trying to execute onBtnBack(); function inside success, but I'm getting this error:

Uncaught ReferenceError: onBtnBack is not defined.

tried to put this.onBtnBack(); but it doesn't work either.

Does anyone know what cause this error?

Thanks!

Upvotes: 1

Views: 1171

Answers (2)

kio21
kio21

Reputation: 711

Another way:

onBtnSave: function() {
    Ext.Ajax.request({
        success: function(response) {
            Ext.Msg.alert('', 'OK', Ext.emptyFn);
            this.onBtnBack();
        },
        scope: this
    });
}

Upvotes: 0

Anand Gupta
Anand Gupta

Reputation: 5700

Try this:

onBtnSave: function (){
 var me = this;
 Ext.Ajax.request({
     success: function(response) {
         Ext.Msg.alert('', 'OK', Ext.emptyFn);
         me.onBtnBack();
     }
 });

Upvotes: 1

Related Questions