Sencha Touch 2 - Changing Views after an Ajax.Request

Go To StackoverFlow.com

0

This may sound weird but ive been banging my head for the past 2 hours because of this problem. I have a function that triggers once I press a login button, when pressed it starts an Ajax Request.

 onEnter: function () {

      Ext.Viewport.mask();

      var email = Ext.getCmp('email').getValue();
      var pass = Ext.getCmp('pw').getValue();
      var consegui = 0;

      Ext.Ajax.request({

       controller: 'AP4.controller.MainCont',

          url: 'myurl',
           method: 'POST',
           callbackKey: 'callback',
          jsonData:{"username":'user', "password":'pass'},


          success: function(result) {
            //Se o webservice nao der erro ele entra aqui, nao quer dizer que tenha 
            //sido correctamente criado session
            // Unmask the viewport
            Ext.Viewport.unmask();
            Ext.Msg.alert("Login Done! Congrats!");
            Ext.Viewport.setActiveItem(this.getRegisto()); **//THIS LINE IS NOT WORKING**

          },         
          failure: function(result){       
            Ext.Msg.alert("Username ou Palavra passe Incorrectas!");        
          },

      });     
 },

For some reason, The setActiveItem is not working and I dont know why. Can anyone help me ?

2012-04-05 16:10
by Akash
Do you get an error - fuzzyLikeSheep 2012-04-05 16:38
the information is not full, what does this.getRegisto() return - Saket Patel 2012-04-05 17:42
Please describe "is not working" better. Do you have any Javascript errors? Check your console - Jay 2012-04-05 21:05
Im sorry if was not clear enough. this.getRegisto() is a view Im tryin to call. What I want, after that Ajax.Request, is to change my view to Registo. it says that there is no such thing as getRegisto() . - Akash 2012-04-06 16:48


1

i think you are accessing this.getRegisto; function in wrong scope, have you checked this keyword points to the object which you want in the success callback?

to change the scope of success callback you can simply add scope argument in the Ext.Ajax.request call, like this

Ext.Ajax.request({
   url: 'myurl',
   method: 'POST',

   success: function(result) {
        // this will point to ViewPort object here
   },

   failure: function(result){
        Ext.Msg.alert("Username ou Palavra passe Incorrectas!");        
   },

   scope : Ext.Viewport     // this is used just for illustration, please specify correct scope here
});
2012-04-06 17:40
by Saket Patel
Thanks! for your help - Akash 2012-04-12 09:20


0

If Registo is in your viewport, why not use setActiveItem(some number) like if Registro is the first item in your viewport then do setActiveItem(0);

2012-04-06 17:21
by fuzzyLikeSheep
Ads