English 中文(简体)
设置在曲奇曲奇内一个值的过期失效
原标题:setting expiry on one value within a jquery cookie

I m 使用 jQuery cookie 设定 3 值 : < code> < ex , < code> < y 和 < code>z 。 我希望 < code> < z 在365 天后过期,但不能过期 < code> x 和 < code> < /code > 。

$.cookie("MyTestCookie", xyz, { expires: 999999 });  

我用下列方法分割了数值:

var xVal =  my_cookie_value.substring(0);
var yVal =  my_cookie_value.substring(1);
var zVal =  my_cookie_value.substring(2);

$.cookie("MyTestCookie", zVal, { expires: 365 }); 

预先将

问题回答

你正在做的是

$.cookie("MyTestCookie", xyz, { expires: 999999 });  
$.cookie("MyTestCookie", zVal, { expires: 365 }); 

这只是将第一个 cookie 替换为第二个 cookie, 并随着名称( MyTestCookie ) 相同而更新值和过期时间

你可以做的是:

$.cookie("X-MyTestCookie", xVal, { expires: 99999 }); 
$.cookie("Y-MyTestCookie", yVal, { expires: 99999 }); 
$.cookie("Z-MyTestCookie", zVal, { expires: 365 }); 

注意 cookie 名称不同( X- MyTestCookie , Y-MyTestCookie _MyTestCookie ) - 这在不同的 cookie 中放置了数值...

$.cookie("MyTestCookie", xVal + "%" + yVal, { expires: 99999 }); 
$.cookie("Z-MyTestCookie", zVal, { expires: 365 }); 

在第一行中, 字符被用作分隔符,以分隔值,然后在获得 cookie 时需要分割值。





相关问题
How to suppress/remove PHP session cookie

I need to suppress an already set session cookie header, but I cannot find any way to do this. Why? I need to make an image, sent by a PHP script, cacheable by the end user; this image is used to ...

Remove Cookies from JS or CSS files

Bizarrely my javascript and css files have cookies (says Firebug). I use Zend Framework and I think it has to do with it. Could I change the .htaccess that CSS or JS files don t link to the ZF or is ...

httplib2, how to set more than one cookie?

As you are probably aware, more often than not, an HTTP server will send more than just a session_id cookie; however, httplib2 handles cookies with a dictionary, like this: response, content = http....

cookies control

what tool wold you recommend me to use in order to see what data are stored in my cookies while i m browsing the net. I m a beginner into webdev field(6 months php experience) and i m curious to see ...