TideSDK如何保存cookie的信息在不同的文件中访问? [英] TideSDK How to save a cookie's information to be accessed in different file?

查看:173
本文介绍了TideSDK如何保存cookie的信息在不同的文件中访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用TideSDK的 Ti .Network 设置我的cookie的名称和值。
但是如何从我的其他页面获取这个cookie的值?

I am trying to use TideSDK's Ti.Network to set the name and value of my cookie. But how do I get this cookie's value from my other pages?

            var httpcli;
            httpcli = Ti.Network.createHTTPCookie();
            httpcli.setName(cname); //cname is my cookie name
            httpcli.setValue(cvalue);  //cvalue is the value that I am going to give my cookie
            alert("COOKIE value is: "+httpcli.getValue()); 

如何从我的下一页检索此Cookie值?提前感谢!

How would I retrieve this cookie value from my next page? Thank you in advance!

推荐答案

确定,有很多方法可以在tidesdk上创建存储内容。 Cookie可以是其中之一,但不是必需的。

ok, there are a lot of ways to create storage content on tidesdk. cookies could be one of them, but not necessary mandatory.

在我的个人反对中,Cookie太限制存储信息,因此我建议您将用户信息存储在JSON文件,因此您可以从单个信息存储到大型结构(取决于项目)。假设你有一个项目,客户端必须存储应用程序配置,如'首选路径'来存储文件或保存字符串(例如名字,姓氏),你可以使用Ti.FileSystem来存储和读取这样的信息。:

In my personal oppinion, cookies are too limited to store information, so I suggest you to store user information in a JSON File, so you can store from single pieces of information to large structures (depending of the project). Supposing you have a project in which the client have to store the app configuration like 'preferred path' to store files or saving strings (such first name, last name) you can use Ti.FileSystem to store and read such information.:

在下面的示例中,我使用jQuery读取文件中存储的json字符串:

in the following example, I use jQuery to read a stored json string in a file:

.json):

{
    "fname" : "erick",
    "lname" : "rodriguez",
    "customFolder" : "c:\\myApp\\userConfig\\"
}

注意:由于某些原因,Tidesdk无法解析一个json结构,因为它将conf.json解释为一个文本文件,因此如果删除所有选项卡和空格,解析将会正常工作:

Note : For some reason, Tidesdk cannot parse a json structure like because it interprets conf.json as a textfile, so the parsing will work if you remove all the tabs and spaces:

{"fname":"erick","lname":"rodriguez","customFolder":"c:\\myApp\\userConfig\\"}

现在让我们读它... 。(myappfolder是您的存储文件夹的路径)

now let's read it.... (myappfolder is the path of your storage folder)

readfi = Ti.Filesystem.getFile(myappfolder,"conf.json");
Stream = Ti.Filesystem.getFileStream(readfi);
Stream.open(Ti.Filesystem.MODE_READ);
contents = Stream.read();
contents = JSON.parse(contents.toString);
console.log(contents);

现在让我们存储.... ....

now let's store it....

function saveFile(pathToFile) {
    var readfi,Stream,contents;
    readfi = Ti.Filesystem.getFile(pathToFile);
    Stream = Ti.Filesystem.getFileStream(readfi);
    Stream.open(Ti.Filesystem.MODE_READ);
    contents = Stream.read();
    return contents.toString();
};

//if a JSON var is defined into js, there is no problem
var jsonObject = {
   "fname":"joe",
   "lname":"doe",
   "customFolder" : "c:\\joe\\folder\\"
}

var file = pathToMyAppStorage + "\\" + "conf.json";
var saved = writeTextFile(file,JSON.stringify(jsonObject));
console.log(saved);

这篇关于TideSDK如何保存cookie的信息在不同的文件中访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆