jQuery 存储会话数据

发布于 2024-08-31 05:50:20 字数 153 浏览 1 评论 0 原文

我正在尝试使用 jQuery AJAX。我的要求是,我希望从数据集中的数据库加载用户名,将其转换为 JSON 格式并将其存储在内存中或使用 jQuery 数据在用户浏览我的网站(即会话)时使用。这样我可以使用自动完成或我自己的代码向用户显示数据。

谁能帮我设计这样一个场景吗?

I am trying to use jQuery AJAX. What my requirement is, i wish to load user names from DB in dataset, convert it to JSON format and store it in memory or using jQuery data for use while a user is browsing my site, i.e for a session. This way I can use autocomplete or my own code to display data to user.

Can anyone help me design such a scenario?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

远昼 2024-09-07 05:50:20

HTML 5 Web 存储

超越 cookie、Google Gears 和专有解决方案

标准化,无需特殊插件。可通过 JavaScript/jQuery 编写脚本。虽然仅在最新的浏览器中受支持,但您可以使用 HTML 5 Web Storage,即 localStoragesessionStorage 属性,旨在在页面请求之间的网站上下文中保留客户端的状态。能容纳的东西比饼干多得多。例如 IE 8 DOM 存储规范 (10 MB 客户端存储),Firefox DOM 存储规范

HTML 5 Web Storage

think beyond cookies, Google Gears and proprietary solutions

Standardized, no special plugin required. Scriptable through JavaScript/jQuery. Although supported only in the latest browsers, you can use HTML 5 Web Storage, namely localStorage and sessionStorage properties, intended to keep state on the client side in context of the website between page requests. Holds a heck of a lot more than cookies. For example IE 8 DOM storage spec (10 MB client-side storage), Firefox DOM storage spec.

寄离 2024-09-07 05:50:20

还有 YUI 2 Storage Utility,它可以为您抽象存储(HTML 5、Google Gears、SWF)取决于浏览器支持的内容:

存储实用程序提供了
存储重要信息的机制
大量文本数据,客户端,
无论您的浏览器是否支持
提议的 HTML 5 存储
规格。

There is also the YUI 2 Storage Utility which abstracts the storage for you (HTML 5, Google Gears, SWF) depending on what the browser supports:

The Storage Utility provides a
mechanism for storing significant
amounts of textual data, client-side,
whether or not your browsers supports
the proposed HTML 5 Storage
specification.

冷默言语 2024-09-07 05:50:20

JQuery 数据可能没有用,因为当您刷新页面从一个页面转到下一个页面时,您将丢失数据,但是您可以使用 COOKIES 来完成此操作 - 有一个 jQuery cookies 插件 这将使您更轻松。

JQuery data may not be useful because you will lose the data when you go from one page to the next as the page is refreshed, you can however do this using COOKIES -- there is a jQuery cookies plugin that will make it easier for you.

娇纵 2024-09-07 05:50:20

会话意味着服务器端。 jQuery 的意思是客户端。你无法在两者之间进行翻译。 Cookie 是您所能期望的最好的保持严格客户端的方式。

Sessions means serverside. jQuery means clientside. You can't translate between the two. Cookies is the best you can hope for to remain strictly clientside.

酒废 2024-09-07 05:50:20

Google Gears 是我所知道的唯一解决方案,但它要求用户安装它并且仅在一些浏览器上运行。但是,当用户说...聚焦于自动完成的搜索框时,您可以使用 $.getJSON 从服务器获取 JSON 编码和 gzip 压缩的用户列表,然后使用激进的客户端资源缓存,以减少数据库的命中次数。

如果它是一个相当长的用户列表,您可能需要考虑使用 memcached 来存储列表,或者可能将其写入文件并由前端服务器直接提供服务(即 Nginx、Lighttpd、Apache:很多避免运行数据库查询的事情)

Google Gears is the only solution I know of for doing this, but it requires the user to install it and only runs on a few browsers. You could, however, use $.getJSON to fetch a list of users, JSON-encoded and gzipped, from your server when the user say... focuses the auto-completed search box, then use aggressive client-side resource caching to reduce the number of hits on your database.

If it's a pretty long list of users, you may want to look into using memcached to store the list, or perhaps writing it to a file and having it be served directly by your front-end server (i.e. Nginx, Lighttpd, Apache: pretty much anything that avoids running a DB query)

万劫不复 2024-09-07 05:50:20

我一直在使用 PersistJS 并取得了巨大的成功,几乎完成了您所描述的工作。它是一个轻量级插件(< 10k),使用以下任何可用后端抽象出客户端存储:

  • flash:Flash 8 持久存储。
  • gears:基于 Google Gears 的持久存储。
  • localstorage:HTML5草稿存储。
  • Whatwg_db:HTML5 草稿数据库存储。
  • globalstorage:HTML5 草稿存储(旧规范)。
  • 即:Internet Explorer 用户数据行为。
  • cookie:基于cookie的持久存储。

它根据浏览器功能和安装的插件透明地选择最佳存储后端。它适用于:

  • globalStorage:Firefox 2.0+、Internet Explorer 8
  • localStorage:开发 WebKit
  • openDatabase:Safari 3.1+
  • 用户数据行为:Internet Explorer 5.5+

...如果其他持久存储选项都不起作用,则可以选择回退到 cookie。 DOM 存储方法至少可以为您提供几兆字节的存储空间;如果您回退到 cookie,您的大小将被限制在大约 4kB。

I've been using PersistJS with great success to do pretty much what you're describing. It's a lightweight plugin (< 10k) that abstracts away client-side storage using any of these available backends:

  • flash: Flash 8 persistent storage.
  • gears: Google Gears-based persistent storage.
  • localstorage: HTML5 draft storage.
  • whatwg_db: HTML5 draft database storage.
  • globalstorage: HTML5 draft storage (old spec).
  • ie: Internet Explorer userdata behaviors.
  • cookie: Cookie-based persistent storage.

It transparently picks the best storage backend based on browser capability and installed plugins. It works with:

  • globalStorage: Firefox 2.0+, Internet Explorer 8
  • localStorage: development WebKit
  • openDatabase: Safari 3.1+
  • userdata behavior: Internet Explorer 5.5+

...and optionally falls back to cookies if none of the other persistent storage options work. The DOM storage methods get you at least a few megabytes worth of storage space; you'll be limited to roughly 4kB if you fall back to cookies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文