2011-12-13 43 views
0

下面是我的程序存儲一些數據,餅乾供以後訪問的結構爲什麼這個cookie返回我空,當我把它從其他函數[IE]

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中。請幫我解決這個問題。

回答

2

嘗試:

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