2014-03-31 27 views
0

我使用的查詢餅乾插件這樣的:Cookie的工作50%

$(document).ready(function(){ 
    $('a.close').click(function(){ 
     var user = $('div.popup article.user').html(); 

     $.cookie('the_cookie', user, {path: "/", domain: "domain.com"}); 
     message = $.cookie('the_cookie'); 

     $('section#sidebar_right').html(message); 
    }); 
}); 

所以,當用戶點擊「關閉按鈕」,該Cookie獲取用戶名,並把它變成一個特定的區域,這

domain.com/test.php#close

當我刷新到這個網站:情況是在這個網站上創建

domain.com/test.php

餅乾消失了(我可以看到這個,因爲顯示的內容消失了)。

有人可以告訴我爲什麼嗎?

問候

編輯:

$(document).ready(function(){ 
$('a.close').click(function(){ 
    var user = $('div.popup article.user').html(); 

    $.cookie('the_cookie', user, {expires: "7",path: "/", domain: "domain.com"}); 
    message = $.cookie('the_cookie'); 

    $('section#sidebar_right').html(message); 
}); 

});

=>仍然沒有工作,任何想法?

回答

1

您尚未設置cookie的生存期,因此它在會話結束時被刪除。

https://github.com/carhartl/jquery-cookie

期滿

到期:365定義的cookie的壽命。值可以是數字 ,它將被解釋爲創建時的日期或日期 對象。如果省略,則Cookie變成會話cookie。

+0

我編輯了我的問題,你可以看一下嗎?問候和感謝! – user3297073

+0

你解決了這個問題嗎?它也可能是服務器覆蓋你的cookie。 –