首页 新闻 会员 周边 捐助

.net 购物车,用ajax +cookies 问题

0
悬赏园豆:40 [待解决问题]

我用ajax+cookies做购物车,修改后 cookies的值不变,这是为什么呀?,代价如下:

 /// <summary>
        /// 将要购买的商品信息写入Cookies
        /// </summary>      
        public void WriteCookies(String ProductID, String Amount)
        {
            HttpContext.Current.Response.Cookies["ShoppingCart"]["ProductID"] = ProductID;
            HttpContext.Current.Response.Cookies["ShoppingCart"]["Amount"] = Amount;
            HttpContext.Current.Response.Cookies["ShoppingCart"].Expires = DateTime.Now.AddDays(60);

            //GetDataFromCookies();
        }

 

修改后

HttpContext.Current.Response.Cookies["ShoppingCart"]["ProductID"] = productId;
            HttpContext.Current.Response.Cookies["ShoppingCart"]["Amount"] = amount;
            HttpContext.Current.Response.Cookies["ShoppingCart"].Expires = DateTime.Now.AddDays(60);

 

修改后的amount数量,变了,,修改完之后,在取值

IList<Product> iList = new List<Product>();
            if (HttpContext.Current.Request.Cookies["ShoppingCart"] != null)
            {
                string[] split = HttpContext.Current.Request.Cookies["ShoppingCart"]["ProductID"].ToString().Trim().Split(new Char[] { ',' });
                string[] splitAmount = HttpContext.Current.Request.Cookies["ShoppingCart"]["Amount"].ToString().Trim().Split(new Char[] { ',' });

                for (int i = 0, j = 0; i < split.Length && j < splitAmount.Length; i++, j++)
                {

后面我就不贴了,  这里取到的值是  splitAmount  是修改之前的值,上面,重新复制后,没取到,这是ajax修改操作,不刷新,就这样,难道不刷新,cookies的值不变吗?

Jason.裕哥的主页 Jason.裕哥 | 初学一级 | 园豆:69
提问于:2010-11-30 14:00
< >
分享
所有回答(2)
0

大哥你的缓存

6945249 | 园豆:0 (初学一级) | 2010-11-30 14:12
0

上次也试过这种写法,无法取到cookie值,后来修改为返回json,然后在callback中进行操作:

 

$.post(loginUrl,data,function(data){
if(data.Result=="False"){
$(
"#message").empty()
.append(
'系统登陆失败,请核对用户名和密码');
}
else{
document.location.href
="main.htm";
$.cookie(
'guid',data.GUID,{expires: 7});
$.cookie(
'name',data.Name,{expires: 7});
}
});

 

wgz | 园豆:1254 (小虾三级) | 2010-12-01 10:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册