首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

js 中Cookie的跨域有关问题

2012-12-15 
js 中Cookie的跨域问题在一台服务器上有这样 一段程序: if (this.Request.Cookies[imgCode] null){im

js 中Cookie的跨域问题
在一台服务器上有这样 一段程序:
 if (this.Request.Cookies["imgCode"] == null)
            {
                imgCookie = new HttpCookie("imgCode");
                imgCookie.Value = random;
                imgCookie.Domain ="http://localhost:59315/"; 
                this.Response.Cookies.Add(imgCookie);     
          }


现在在一个静态页面中有一段JS是去调用这个程序中的数据的。但是,JS中

   //获取指定名称的cookie的值
function getCookie(objName) {
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
    }

function Code_Written() {
      var vCode = ((document.getElementById("TB_code").value)).toLowerCase().trim(); 
      if (vCode != "") {
         //判断验证码是否正确             
        var code = getCookie("imgCode");  ;  
         //正确
         if (code.toLowerCase() == vCode) {
              return true;
        }    
    }
function readCookie() {

    //判断是否存在cookie
   
    var isExist = document.cookie.indexOf("imgCode=");

    //alert(isExist);
    if (isExist != -1) {
        //“imgCode=”后面的等号的位置
        var c = document.cookie.indexOf("=", isExist) + 1;
        //获取等号后面的字符串,也就是所需要的验证码!
        var str = document.cookie.substring(c)
        //alert(document.cookie.substring(c));

        if (document.getElementById("Image").value != str) {

            document.getElementById("Image").select();
            document.getElementById("imgCode").src = "http://localhost:59315/shortcut/code.aspx?abc=" + Math.random();
            alert("验证码输入错误!")
            return false;
        } else {
            return true;


        }
    }
}


现在运行时总是提示为空。也就是得不到cookie。
[最优解释]
http://wenku.baidu.com/view/5286e7f6f61fb7360b4c6540.html
[其他解释]
怎么没人回答呢?自己给自己顶一个吧
[其他解释]
该回复于2011-12-16 17:07:42被版主删除
[其他解释]
该回复于2011-12-30 15:55:36被版主删除
[其他解释]

引用:
http://wenku.baidu.com/view/5286e7f6f61fb7360b4c6540.html


你拣着便宜了。没人给我回答,就你一个来顶了。我着急结贴,分数全部给你了、

热点排行