Reputation: 2564
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?
Upvotes: 1
Views: 5680
Reputation: 145162
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:
It transparently picks the best storage backend based on browser capability and installed plugins. It works with:
...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.
Upvotes: 0
Reputation: 28917
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.
Upvotes: 4
Reputation: 19045
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.
Upvotes: 1
Reputation: 2284
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)
Upvotes: 0
Reputation: 16035
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.
Upvotes: 0
Reputation: 10363
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.
Upvotes: 0