在浏览器中存储持久性数据 [英] Storing persistent data in browser

查看:120
本文介绍了在浏览器中存储持久性数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的web应用程序,我需要存储跨多个页面的表单输入,直到我终于处理/操纵它们以产生一些结果(它主要格式化输入的数据并以某种布局呈现它)。我认为我的选项是 -

For my web application, I need to store form inputs spanning across multiple pages, until I finally process/manipulate them to produce some results (its mostly formatting the data entered and presenting it in some layout). The options I think I have are -


  1. 继续发送用户的输入到服务器,存储在一些数据库,做

  1. Keep sending user's inputs to the server, store it there in some database, do the final manipulation there only, and show the result.

当用户填写表单时,将输入存储在浏览器的存储中,最后使用此存储的数据进行操作和显示结果。

Store the inputs in browser's storage as the user fills the forms, and finally use this stored data to manipulate and show results.

我非常想使用第二种方法,也许一种可能的方式是使用Cookie,恐怕我可能会碰到一些cookie数据存储的上限。我也愿意理解第一种方法的优点,或任何第三种方法。

I very much want to use the second method, and perhaps a possible way is using cookies, but I'm afraid I might just hit some upper limit of cookie data storage. I'm also open to understanding the merits of the first method, or any third method.

谢谢。

推荐答案

达到cookie的存储限制可能表明您尝试在客户端存储过多。将服务器端存储在会话等内容中可能是谨慎的。会话的键可以存储在cookie中。

Hitting the storage limit of the cookie could indicate you are trying to store too much on the client side. It might be prudent to store it serverside, in something like a session. The key to the session could then be stored in a cookie.

另一种方法是不让请求跨越多个页面,而只是将数据存储在客户端,不是作为cookie,而是作为不同的表单字段和/或文本字段(它们可以被隐藏)。这种方法的优点是它不会达到cookie限制,因为你有。它还使您的服务器代码更容易/更清洁,因为它不必跟踪状态(如果跨越页面,你总是必须做的事情,因此你首先击中cookie限制的原因) 。

An alternative method is to not have the requests span multiple pages, and just store the data on the client side, not as a cookie, but as different form fields and/or text fields (they could be hidden). The merit of such a method is it doesnt hit the cookie limit as you have. It also makes your serverside code easier/cleaner, since it doesn't have to keep track of state (something you'd always have to do if spanning across pages, and thus the reason you are hitting the cookie limit in the first place).

这篇关于在浏览器中存储持久性数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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