2012-11-09 182 views
1

我在sencha touch 2中创建了一个ajax请求,当我收到成功消息时,如何设置返回值给会话,还请告诉我通过哪种方式获取会话中的值也。Sencha Touch 2 Session Storage

submitLoginForm: function() { 
    var form = this.getLoginForm().getValues(); 

    Ext.Ajax.request({ 
     url: '../../authenticate.php', 
     method: 'POST', 

     params: { 
      email: form.email, 
      password: form.password 
     }, 

     success: function(response) { 
      var json = Ext.decode(response.responseText); 
      if(json.message == 'success') { 
       Ext.Msg.alert('Login Success.....'); 
       //Here i want to store return data in session 
      } else { 
       Ext.Msg.alert('Invalid Login Or Password.....'); 
      } 
     }, 

     failure: function(response) { 
      Ext.Msg.alert('The request failed.....'); 
     } 
    }); 
}, 

回答

1

上成功响应,使用HTML5本地存储设置和获取会话变量:

var sessionObject = { 'var1': 1, 'var2': 2, 'var3': 3 }; 

// Put the session object into storage 
localStorage.setItem('sessionObject ', JSON.stringify(sessionObject)); 

// Retrieve the session object from storage 
var sessionObject = localStorage.getItem('sessionObject '); 

console.log('sessionObject : ', JSON.parse(sessionObject));