localStorage保存会话对象

时间:2015-07-31 09:02:52

标签: javascript session local-storage

我正在尝试将应用程序检索到的服务器上的数据库中的用户数据加载到localStorage,但在成功登录后,程序根本没有保存会话。我已经反复测试过 - 检查过Typo&s;并尝试将对象转换为普通数组,但我仍然遇到同样的错误:

  

错误:保存到本地存储。 80 $ 00 #nf错误:TypeError:无法读取   财产'拆分'未定义的

这是我用来存储会话数据的功能

function SaveSession($AjaxData) {

    if (!!window.localStorage) 
    {   
        try {
       //Saving array data to local storage
        var client = new Object();
        var ArrLngth = $AjaxData.length;
        var categories = [ "FullName", "CompanyName", "Profession", "cell", "country", "usern", "email", "passw"];
        var $l = 0;
        var $AjaxSplit = [];

            while($l <= ArrLngth) {
                $AjaxSplit = $AjaxData[$l].split(" = "); 
                found = $k.inArray($AjaxSplit[0], categories);

                if(found != '-1')   {
                    switch(found)                   
                    {
                        case 0:
                            client.Fullname = $AjaxSplit[1];
                        break;

                        case 1:
                            client.Company =  $AjaxSplit[1];
                        break;

                        case 2:
                            client.Title = $AjaxSplit[1];
                        break;

                        case 3:
                            client.Mobile =  $AjaxSplit[1];
                        break;

                        case 4:
                            client.country =  $AjaxSplit[1];
                        break;

                        case 5:
                            client.usern =  $AjaxSplit[1];              
                        break;

                        case 6:
                            client.email =  $AjaxSplit[1];
                        break;

                        case 7:
                            client.password =  $AjaxSplit[1];
                        break;

                    }

                }

                $l++;
            }

        window.localStorage.setItem("client", JSON.stringify(client));
        } 
        catch (exception) {
                console.log("Error: Saving to local storage.\n\r " +client.password+" Error: "+exception);
        }
    }
    else {
        alert('ERRROR Local not supported!!!'); 
    }

};

我也尝试过单独存储数据值......我还缺少什么或者没有正确执行?

0 个答案:

没有答案