2012-11-09 222 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));