添加和使用jQuery / AJAX没有显示数据库中最喜欢的名称列表

问题描述:

使用我的网站的人可以搜索在世界的任何名称。用户可以添加自己的特别的名字最喜爱的清单。每个用户都可以看到另一个页面他们最喜欢的名称列表(名称那些由用户在一个会话中添加)。你可以建议做这个使用jQuery / AJAX一个最好的方法。 Thankz。

using my website people can search any names in world. users can add their particular name to favorite list. each user can see their favorite names list in another page(names those added by user in one session). can you suggest a best method to do this using jquery/ajax. Thankz.

您可以使用的本地存储保存数据。它的工作原理那么容易,因为这样的:

You could use local storage to save the data. It works as easy as this:

localStorage.setItem('key', 'value');
localStorage.getItem('key'); // returns 'value'

您可以用递增键保存名称:

You could save the names using an incrementing key:

localStorage.setItem('name-' + (localStorage.length + 1).toString(), 'favName');
// Names stored as 'name-0', 'name1', ...

然后,检索列表:

And then, to retrieve the list:

var names = new Array();

if (localStorage) {
    if (localStorage.length) {
       for (var i = 0; i < localStorage.length; i++) {
           names[i] = localStorage.getItem('name-' + i.toString());
       }
    } else {
       names[0] = 'You have no favorite names stored';
    }
}

有一些插件提供的回退在不支持的网络存储(即使是在IE6)浏览器,如的的TotalStorage jstorage

There are some plugins that provide fallbacks on browsers that don't support web storage (Even on ie6), like totalStorage or jstorage.