============================问题描述第一步:我在一个asp页面里设置了Cookie
第二步:在一个html页面里尝试获取这个Cookie   获取结果正常
第三步:在这个html页面里重新设置这个Cookie的值
第三步:在asp页面里再次重新设置这个Cookie的值  获取结果不正常,得到的值竟然是html页面里设置的值
请问这是什么原因呢?感谢

解决方案 »

  1.   

    domain=domainname; Setting the domain of the cookie allows pages on a domain made up of more than one server to share cookie information.  
    path=path; Setting a path for the cookie allows the current document to share cookie information with other pages within the same domain—that is, if the path is set to /thispathname, all pages in /thispathname and all pages in subfolders of /thispathname can access the same cookie information.  cookie是有上述两个参数的.如果想两个文件间的cookie互不影响的话,需要对上述两个属性按情况进行不同设定.
      

  2.   

    因为html页面里重新设置这个Cookie的值是在客户端执行,
    在asp页面里再次重新设置这个Cookie的值是在服务器端执行,
    客户端在服务器端后面执行,当然就是最后设置的Cookie的值了。
      

  3.   

    Asp:设置COOKIES --->Html:获取COOKIES[结果正常]--->Html:重设置COOKIES--->Asp:重设置COOKIES---Html:获取COOKIES按上面的流程,最后结果应该是最后ASP重设置的值   
    可显示的却是HTML重设置的值
      

  4.   

    ---------------在ASP页面中的JS代码//写cookies函数 
    function SetCookie(name,value) //两个参数,一个是cookie的名子,一个是值
    {
      var Days = 10; //此 cookie 将被保存 10 天
      var exp  = new Date();    //new Date("December 31, 9998");
      exp.setTime(exp.getTime() + Days*24*60*60*1000);
      document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }
    //取cookies函数  
    function getCookie(name)       
    {
      var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
      if(arr != null) 
         return unescape(arr[2]); 
         return null;
    }
    function delCookie(name)//删除cookie
    {
      var exp = new Date();

      exp.setTime(exp.getTime() - 1);

      var cval=getCookie(name);

      if(cval!=null) 
           document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }//测试数据
    SetCookie("test","hello javascript");
    ------------------------在HTML中的JS代码//写cookies函数 
    function SetCookie(name,value) //两个参数,一个是cookie的名子,一个是值
    {
      var Days = 10; //此 cookie 将被保存 10 天
      var exp  = new Date();    //new Date("December 31, 9998");
      exp.setTime(exp.getTime() + Days*24*60*60*1000);
      document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }
    //取cookies函数  
    function getCookie(name)       
    {
      var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
      if(arr != null) 
         return unescape(arr[2]); 
         return null;
    }
    function delCookie(name)//删除cookie
    {
      var exp = new Date();

      exp.setTime(exp.getTime() - 1);

      var cval=getCookie(name);

      if(cval!=null) 
           document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }//读取COOKIE
    alert(getCookie("test"));//在HTML页面设置COOKIE
    SetCookie("test","hello java");
    页面运行顺序:
    ASP-->HTML-->ASP-->HTML最后alert()结果应该是 "hello javascript"
    可我这儿出现的是"hello java" 
      

  5.   

    更新cookie前,可以先调用delCookie(name)函数.