如何使用JS写Cookie,用Cookie保存一个集合,具体代码 求高人指点 我想实现一个JS的购物车,就可能会用到Cookie,我就做纯Aajx效果, 具体如下:页面有一张表的数据, 我选中一行 点击放入购物车按钮 就保存一条信息 这条信息是放入Cookie中的, 然后点取回按钮 就是读取Cookie里面的内容数据 ; 望大神指点. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 既然都用ajax了,为什么不直接将数据保存到服务端?用户关闭了Cookie功能你就没办法了 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="获取Cookie.aspx.cs" Inherits="WebApplication1.获取Cookie" %><!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 runat="server"> <title></title> <script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script> <script type="text/javascript"> $(function () { var ids = "1,2,3,4,5,"; var userID = 22; $("#Button1").click(function () { $.ajax({ url: "Handgoods.ashx", type: "post", data: { id: ids, userID: userID, type: "add" }, success: function (msg) { if (msg != "") { $("#addGoods").html("<font color='red'>放入购物车成功</font>"); } } }); }); $("#Button2").click(function () { $.ajax({ url: "Handgoods.ashx", type: "post", data: { userID: userID, type: "read" }, success: function (read) { if (read != "") { $("#getGoods").html("<font color='red'>"+read+"</font>"); } else { $("#getGoods").html("<font color='red'>读取失败</font>"); } } }); }); }); </script></head><body> <form id="form1" runat="server"> <div> <input id="Button1" type="button" value="加入购物车" /> <div id="addGoods" style="font-size: 12px;"> </div> <input id="Button2" type="button" value="显示购物车" /> <div id="getGoods"> </div> </div> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace WebApplication1{ /// <summary> /// Handgoods 的摘要说明 /// </summary> public class Handgoods : IHttpHandler { public void ProcessRequest(HttpContext context) { string goodsID = context.Request["id"]; int userID = int.Parse(context.Request["userID"]);//int.Parse(context.Request["userID"])如果为空就会报错,而如果context.Request["userID"]为空,那么userID就为0 if (context.Request["type"] == "add") { try { string[] goodsIDList = goodsID.ToString().Split(new Char[] { ',' }); int goodsListCount = goodsIDList.Count(); string goodsNewID = null; for (int i = 0; i < goodsListCount; i++) { goodsNewID += goodsIDList[i]; } HttpCookie cookie = new HttpCookie(goodsID);//初使化并设置Cookie的名称 cookie.Expires = DateTime.Now.AddMinutes(10); cookie.Values.Add("", goodsNewID); context.Response.AppendCookie(cookie); context.Response.Write("成功"); } catch (Exception ex) { context.Response.Write(ex.ToString()); } } if (context.Request["type"] == "read") { try { if (context.Request.Cookies[goodsID] != null) { string cookID = context.Request.Cookies[goodsID].Value; context.Response.Write(cookID); } else { context.Response.Write("为空"); } } catch (Exception ex) { context.Response.Write(ex.ToString()); } } } public bool IsReusable { get { return false; } } }} 请问谁知道ASPxNavBar是否具有记忆功能? 做个一个B/S的项目,如果不用每页都验证Session,有更简便的方法吗?谢谢! 关于使用CDO将Html转换成Mht的问题 请问下下面这个功能怎么实现,用什么控件能实现 CSDN 2006年度最有价值专家MVP评选活动 高手救命--关于数据为与TreeView控件生成无限级别的动态菜单问题! 在DataGrid中帮定图片 不能这样写????怪!~ GridView 数据绑定 在vb.net中如何调用可执行文件 我说。。。我悲催的WPF程序。。 一个很简单的问题。关于代码的执行速度。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="获取Cookie.aspx.cs" Inherits="WebApplication1.获取Cookie" %><!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 runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(function () {
var ids = "1,2,3,4,5,"; var userID = 22;
$("#Button1").click(function () {
$.ajax({
url: "Handgoods.ashx",
type: "post",
data: { id: ids, userID: userID, type: "add" },
success: function (msg) {
if (msg != "") {
$("#addGoods").html("<font color='red'>放入购物车成功</font>");
}
}
});
});
$("#Button2").click(function () {
$.ajax({
url: "Handgoods.ashx",
type: "post",
data: { userID: userID, type: "read" },
success: function (read) {
if (read != "") {
$("#getGoods").html("<font color='red'>"+read+"</font>");
}
else {
$("#getGoods").html("<font color='red'>读取失败</font>");
}
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="加入购物车" />
<div id="addGoods" style="font-size: 12px;">
</div>
<input id="Button2" type="button" value="显示购物车" />
<div id="getGoods">
</div>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;namespace WebApplication1
{
/// <summary>
/// Handgoods 的摘要说明
/// </summary>
public class Handgoods : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
string goodsID = context.Request["id"];
int userID = int.Parse(context.Request["userID"]);//int.Parse(context.Request["userID"])如果为空就会报错,而如果context.Request["userID"]为空,那么userID就为0
if (context.Request["type"] == "add")
{
try
{
string[] goodsIDList = goodsID.ToString().Split(new Char[] { ',' });
int goodsListCount = goodsIDList.Count();
string goodsNewID = null;
for (int i = 0; i < goodsListCount; i++)
{
goodsNewID += goodsIDList[i];
}
HttpCookie cookie = new HttpCookie(goodsID);//初使化并设置Cookie的名称
cookie.Expires = DateTime.Now.AddMinutes(10);
cookie.Values.Add("", goodsNewID);
context.Response.AppendCookie(cookie);
context.Response.Write("成功");
}
catch (Exception ex)
{
context.Response.Write(ex.ToString());
}
}
if (context.Request["type"] == "read")
{
try
{
if (context.Request.Cookies[goodsID] != null)
{
string cookID = context.Request.Cookies[goodsID].Value;
context.Response.Write(cookID);
}
else
{
context.Response.Write("为空");
}
}
catch (Exception ex)
{
context.Response.Write(ex.ToString());
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}