javascript Cookie 的其他替代品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8488377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Other Alternatives to Cookies
提问by Exception
I am using cookies to store data at client end for later access. But my concern is I am unable to set more than 20 cookies and I am looking for alternative to cookies.
Please help me on this
我正在使用 cookie 在客户端存储数据以供以后访问。但我担心的是我无法设置超过 20 个 cookie,我正在寻找 cookie 的替代品。
请帮我解决这个问题
Updated
I found jStorage plugin hereBut it does not work for me in this case..
我在这里找到了 jStorage 插件但在这种情况下它对我不起作用..
回答by Pavan
You can leverage local/session storage of HTML5
您可以利用 HTML5 的本地/会话存储
To save a value:
要保存值:
localStorage.name = "Bob";
To get a value:
获取值:
alert(localStorage.name);
回答by Quentin
The two main options are Web Storage and Web SQL Database.
两个主要选项是Web Storage 和 Web SQL Database。
回答by Dave Child
Are you storing one piece of information in each cookie? Because you could use JSON serializationto store more data in each individual cookie.
您是否在每个 cookie 中存储一条信息?因为您可以使用JSON 序列化在每个单独的 cookie 中存储更多数据。
回答by Sandeep G B
There are few alternatives to cookies
cookie 的替代品很少
Session (server side)
If HTML5 compliant browser then you can even have client side database
会话(服务器端)
如果 HTML5 兼容浏览器,那么您甚至可以拥有客户端数据库
回答by lorenzo-s
You can store only one cookie representing a session ID (for example, an alfanumeric randomly generated long string). Then you just need a database to store all your data (that now is on 20 cookies) together with that session ID. At runtime, you read from the only cookie the session ID, and load from the DB all data.
您只能存储一个代表会话 ID 的 cookie(例如,随机生成的字母数字长字符串)。然后你只需要一个数据库来存储你的所有数据(现在是 20 个 cookie)以及该会话 ID。在运行时,您从唯一的 cookie 中读取会话 ID,并从数据库加载所有数据。