最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery cookie extension will set a cookie with a path but will not read it - Stack Overflow

programmeradmin5浏览0评论

First, set a cookie:

jQuery.cookie('monster', 'big', { path : '/sesame/'});

Next, try to read it:

jQuery.cookie('monster');

Firefox tells me that the cookie has indeed been set. The value is big and the path is /sesame/. And yet when I tried to read the cookie it wouldn't work.

Alternate version of the question: How do I specify the path when reading a cookie?

As an experiment I used the following syntax but it sets a cookie rather than read one.

$.cookie('cookie_name', { path: '/path/' });

First, set a cookie:

jQuery.cookie('monster', 'big', { path : '/sesame/'});

Next, try to read it:

jQuery.cookie('monster');

Firefox tells me that the cookie has indeed been set. The value is big and the path is /sesame/. And yet when I tried to read the cookie it wouldn't work.

Alternate version of the question: How do I specify the path when reading a cookie?

As an experiment I used the following syntax but it sets a cookie rather than read one.

$.cookie('cookie_name', { path: '/path/' });
Share Improve this question edited Aug 20, 2010 at 20:00 Manoj Govindan asked Aug 20, 2010 at 11:49 Manoj GovindanManoj Govindan 74.7k21 gold badges137 silver badges142 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

JQuery cookie extension searches the document.cookie attribute to find a cookie and read its value. Document.cookie will only return the name, value pairs for cookies under the current document path. It does however allow you to set a cookie for a path different from the current document path.

Therefore this is not a limitation/bug in the jQuery cookie plugin; rather it is a byproduct of how cookies are handled in Javascript.

Browser will not send cookie to the path its not set to!

Browser sends only cookie name and value. There is no way to find out cookie path or expiration time.

发布评论

评论列表(0)

  1. 暂无评论