当我从其他函数调用它时,为什么这个cookie会返回null [IE]

时间:2011-12-13 10:30:31

标签: jquery xml

以下是我的程序结构,用于将一些数据存储在cookie中供以后访问

function xmlSet()
{
   var qTypes = ["Single","Multi","Grid","Open","Grid3D"];
   for(var i = 0;i<qTypes.length;i++)
   {
        SingleReader(qTypes[i]);
   }
}

function SingleReader(eleType)
{
  var xmlDat = $.parseXML($('#xmlText').val());
  var xml = $(xmlDat);
  var path = xml.find('ProjectID').text();
  xml.find(''+eleType+'').each(function(){
    var id = $(this).attr('name');
    var dat = $(this).text('');
    $.cookies.set(id,dat);
    //Here I am testing whether cookie is being stored or not  
    alert($.cookies.get(id)); // Returns value which was before.  
  };
  alert($.cookies.get("M")) // Here "M" is known Item but it returns me null when I access outside the function
}

这仅在IE中发生。请帮帮我,

1 个答案:

答案 0 :(得分:2)

尝试:

$.cookie('cookie_name', 'our value', { path: '/', expires: 10000 });
//then try alerting out of function