jquery.cookie.js结合asp.net实现最近浏览记录
一、html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>最近浏览记录</title>
<script type="text/javascript" src="/scripts/jquery/jquery-1.10.2.min.js"></script>
<script src="/scripts/json.js" type="text/javascript"></script>
<script src="/scripts/jquery/jquery.cookie.js" type="text/javascript"></script>
<script>
(function ($) { $.history = function (e) {
var e = $.extend({
cookieName: "PrdIDCookie", //cookie名称
nid: 100, //最新访问的商品ID
N: 5 //设置cookie保存的浏览记录的条数
}, e)
var fn = {
cutstr:function(str, len, chr) {
var temp;
var icount = 0;
var patrn = /[^\x00-\xff]/;
var strre = "";
for (var i = 0; i < str.length; i++) {
if (icount < len - 1) {
temp = str.substr(i, 1);
if (patrn.exec(temp) == null) {
icount = icount + 1
} else {
icount = icount + 2
}
strre += temp
} else {
break
}
}
return typeof(chr)=="undefined"? strre:strre + chr;
},
//记录最近浏览过的商品
record: function () {
var _historyp;
if ($.cookie(e.cookieName) == null) { //cookie 不存在
$.cookie(e.cookieName, e.nid, { expires: 7, path: '/' }); //创建新的cookie,保存浏览记录
} else { //cookies已经存在
_historyp = $.cookie(e.cookieName); //获取浏览过的商品编号ID
};
var pArray = _historyp.split(','); //分解字符串为数组
_historyp = e.nid; //最新访问的商品编号放置载最前面
var count = 0; //判断是该商品编号是否存在于最近访问的记录里面
for (var i = 0; i < pArray.length; i++) {
if (pArray[i] != e.nid) {
_historyp = _historyp + "," + pArray[i];
count++;
if (count == e.N - 1) {
break;
}
}
}
$.cookie(e.cookieName, _historyp); //修改cookie的值
},
bind: function () { //获取最近浏览过的商品
var _historyp = "";
if ($.cookie(e.cookieName) != null) { //cookie 不存在
_historyp = $.cookie(e.cookieName); //获取浏览过的商品ID
}
if (_historyp == null && _historyp == "") {
return;
} else {
var prdIDs = []; //将商品ID以列表或数据的方式保存
var pArray = _historyp.split(',');
for (var i = 0; i < pArray.length; i++) {
if (pArray[i] != "") {
//alert(pArray[i]);
prdIDs.push(pArray[i]);
}
}
//--->请求商品详细详细...
$.post('/tools/submit_ajax.ashx?action=get_history_log', { id_arr: prdIDs.toString() }, function (data) {
var data = JSON.parse(data);
var list = '';
if (data) {
for (var i = 0; i < data.length; i++) {
list += '<li><a href="/fy/show/' + data[i].id + '.html"><font style="color:#0041d9">' + fn.cutstr(data[i].title,20) + '</font>-<font style="color:#ff6600">' + data[i].price + '元/平米.天</font></a></li>';
}
}
$("#history_log").html(list);
});
}
}
}
return fn;
}
})(jQuery)
$.history({
cookieName: "PrdIDCookie",
nid: 1628,
N: 5
}).record();
$.history().bind();
</script>
</head> <body>
<ul id="history_log"></ul>
</body>
</html>
asp.net处理代码
private void get_history_log(HttpContext context)
{
string id = DTRequest.GetFormString("id_arr");
DataTable dt = new BLL.article().Getdata_List("housing", 5, "id in(" + id + ")", "sort_id asc").Tables[0];
var list = new List<object>();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
list.Add(new { id = dr["id"], title = dr["title"], price = dr["price"] });
}
context.Response.Write(new JavaScriptSerializer().Serialize(list));
return;
}
jquery.cookie.js结合asp.net实现最近浏览记录的更多相关文章
- jquery.cookie.js 删除cookie
简单交代一下背景:asp.net页面的上的切换登录按钮的点击事件实现cookie的删除. 但是好像没办法直接删除,通过网上提供的方法,可以使用jquery.cookie.js 来操作cookie的创建 ...
- JavaScript-Tool:jquery.cookie.js
ylbtech-JavaScript-Tool:jquery.cookie.js 1.返回顶部 1.jquery.cookie.js /*! * jQuery Cookie Plugin v1.4.0 ...
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
Cookie是网站设计者放置在客户端的小文本文件.Cookie能为用户提供很多的使得,例如购物网站存储用户曾经浏览过的产品列表,或者门户网站记住用户喜欢选择浏览哪类新闻. 在用户允许的情况下,还可以存 ...
- jquery.cookie.js && java后台代码 操作cookie实现记住当前用户输入信息代码
下载jquery.cookie.js地址看这里:http://pan.baidu.com/s/1gdCPaN5 //初始化页面时验证是否记住了密码 $(document).ready(function ...
- 【转】jquery.cookie.js的使用
Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将Cookie的key/value保存到某个目录下的文本文件内,下次请求同一网站时就发送该Cookie给服务器(前提是 ...
- jquery.cookie.js 操作cookie实现记住密码功能的实现代码
jquery.cookie.js操作cookie实现记住密码功能,很简单很强大,喜欢的朋友可以参考下. 复制代码代码如下: //初始化页面时验证是否记住了密码 $(document).ready( ...
- Jquery.cookie.js 源码和使用方法
jquery.cookie.js源码和使用方法 jQuery操作cookie的插件,大概的使用方法如下 $.cookie(‘the_cookie’); //读取Cookie值$.cookie(’the ...
- jQuery.cookie.js插件了解及使用方法
jquery.cookie.js插件实现浏览器的cookie存储,该插件是基于jquery开发,方便cookie使用. jquerycookie.js的下载地址 http://plugins.jque ...
- jquery.cookie.js使用
1.下载jquery.cookie.js 官网:http://plugins.jquery.com/cookie/ 或 http://pan.baidu.com/s/1mgynA8g 2.使用方法 $ ...
随机推荐
- Delphi中StrToDateTime函数TFormatSettings参数的使用
var FSetting : TFormatSettings; DateTime1: tDateTime; begin FSetting := TFormatSettings.Cr ...
- javascript:apply方法
1. apply和call的区别在哪里 2. 什么情况下用apply,什么情况下用call 3. apply的其他巧妙用法(一般在什么情况下可以使用apply ...
- Java泛型中的标记符含义:
Java泛型中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number( ...
- python测试开发django-32.admin后台多对多关系ManyToManyField
前言 一本书可以有多个作者,一个作者也可以写多本书,这种关系就是本篇要说的多对多关系. 这种场景在django里面数据库设计时候,需要用到ManyToManyField方法 多对多表设计 auther ...
- FEC详解三
转自:http://blog.csdn.net/Stone_OverLooking/article/details/77752076 继续上文讲解: 3) 标准的RTP头结构如下所示: 其中第一个字节 ...
- 实用ExtJS教程100例-005:自定义对话框Ext.MessageBox.show
我们对ExtJS对话框进行了三篇演示: MessageBox的三种用法 进度条对话框Ext.MessageBox.progress 等待对话框Ext.MessageBox.wait 通过上面三篇内容的 ...
- 用SAX和PULL进行XML文件的解析与生成
XML解析有传统的dom方法还有Jsoup,SAX,PULL等,这里讲的是比较省内存的SAX和PULL方法.Android中极力推荐用PULL的方式来解析,我个人觉得pull确实比较简单,但其内部的逻 ...
- 《“胡”说IC——菜鸟工程师完美进阶》
<“胡”说IC——菜鸟工程师完美进阶> 基本信息 作者: 胡运旺 出版社:电子工业出版社 ISBN:9787121229107 上架时间:2014-5-15 出版日期:2014 年5月 开 ...
- information_schema系列六(索引,表空间,权限,约束相关表)
information_schema系列六(索引,表空间,权限,约束相关表) 1: STATISTICS 这个表提供的是关于表的索引信息: INFORMATION_SCHEMA Name SHOW ...
- npm ERR! Error extracting ~/.npm/cloudant/1.9.0/package.tgz archive: ENOENT: no such file or directory, open '~/.npm/cloudant/1.9.0/package.tgz'
修改package.json Thanks machines returning the above error when , just and now all the builds are pass ...