商品最近浏览历史记录

<script type="text/javascript">
 //插件/*JCookie.js * /
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};

</script>

<script type="text/javascript">

 $(document).ready(function(){
var historyp;
//最新访问的商品编号id
var nid=$("#hdPvId").val();
//设置cookie保存的浏览记录的条数
var n=8;
var count=0;
var check_result = $('#show');
// 判断是否存在cookie
if($.cookie('star')==null) //cookie不存在
{
   var k=0;
  // 创建新的cookie,保存浏览记录
   $.cookie('star',nid,{expires:7,path:'/'});
  //$.cookie('smile1314h',nid,{expires:7,path:'/',domain:'smile1314.com',secure:true});
    $.ajax({ //一个ajax过程
      type: "get",
      url : "../getlatestproduct.aspx",
      datatype:'xml',
      data: "p_id="+nid,
      success:function(data)
      {
           $(data).find('Product').each(function()
           {
                k++;
                var $co=$(this);
                var price=$co.find('price').text();
                var imageUrl=$co.find('imageUrl').text();
                var productName=$co.find('productName').text();  
                var url=$co.find('url').text();
                if(k==1)
                {     
                   check_result.append("<div class=\"show-item active\"><span class=\"img\"><a href=\""+url+"\"> <img src=\""+imageUrl+"\" width=\"41px\" height=\"41px\" alt=\""+productName+"\" /></a></span> <span class=\"name\"><a href=\""+url+"\">"+productName+"</a></span> <span class=\"price\">"+price+"</span></div>");
                }
                else
                {
                   check_result.append("<div class=\"show-item\"><span class=\"img\"><a href=\""+url+"\"><img src=\""+imageUrl+"\" width=\"41px\" height=\"41px\" alt=\""+productName+"\" /></a></span> <span class=\"name\"><a href=\""+url+"\">"+productName+"</a></span> <span class=\"price\">"+price+"</span></div>");
                }
            });
        }
        //check_result.append("");
    });
}
else //cookies已经存在
{
     //获取浏览过的商品编号id
     historyp=$.cookie('star');
      //分解字符串为数组
    var parray=historyp.split(',');
    //最新访问的商品编号放置载最前面
    historyp=nid;
    // 判断是该商品编号是否存在于最近访问的记录里面
    for(var i=0;i<parray.length;i++)
    {
       if(parray[i]!=nid)
       {
          historyp=historyp+","+parray[i];
          count++;
          if(count==n-1)
          {
            break;
          }
       }
    }
    //check_result.html('<img src=/css/image/loading.gif style=/"margin-left:40px;;/">');
    var j=0;
   //ajax 根据产品编号获取信息列表
    $.ajax({ //一个ajax过程
      type: "get",
      url : "../getlatestproduct.aspx",
      datatype:'xml',
      data: "p_id="+historyp,
      success:function(data)
      {
           check_result.html("");
           $(data).find('Product').each(function()
           {
                j++;
                var $co=$(this);
                var price=$co.find('price').text();
                var imageUrl=$co.find('imageUrl').text();
                var productName=$co.find('productName').text();  
                var url=$co.find('url').text();
                if(j==1)
                {     
                   check_result.append("<div class=\"show-item active\"><span class=\"img\"><a href=\""+url+"\"> <img src=\""+imageUrl+"\" height=\"41px\" width=\"41px\" alt=\""+productName+"\" /></a></span> <span class=\"name\"><a href=\""+url+"\">"+productName+"</a></span> <span class=\"price\">"+price+"</span></div>");
                }
                else
                {
                   check_result.append("<div class=\"show-item\"><span class=\"img\"><a href=\""+url+"\"><img src=\""+imageUrl+"\" height=\"41px\" width=\"41px\" alt=\""+productName+"\" /></a></span> <span class=\"name\"><a href=\""+url+"\">"+productName+"</a></span> <span class=\"price\">"+price+"</span></div>");
                }
            });
        }
        //check_result.append("");
    });
 
   //修改cookie的值
  $.cookie('star',historyp);
}
})

</script>

            Response.Clear(); //首先清空Response对象
            Response.ContentType = "text/xml";//设置返回数据的数据类型
            Response.Charset= "GB2312";//设置数据的编码
            createXml();
            Response.End();



            StringBuilder sbXml = new StringBuilder();
            sbXml.AppendLine(@"<?xml version='1.0' encoding='UTF-8'?>");
            sbXml.AppendLine(@"<photolist>");
            while (sdr.Read()) {
                string title = sdr["title"].ToString();
                string photo = sdr["photo"].ToString();
                sbXml.AppendLine(@"<photo>");
                sbXml.AppendLine(@"<title>" + title + "</title>");
                sbXml.AppendLine(@"<url>" + photo + "</url>");
                sbXml.AppendLine(@"</photo>");
            }
            sbXml.AppendLine(@"</photolist>");
            Response.Write(sbXml.ToString());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值