JQuery cookie 扩展将设置一个带有路径的 cookie,但不会读取它
首先,设置一个 cookie:
jQuery.cookie('monster', 'big', { path : '/sesame/'});
接下来,尝试读取它:
jQuery.cookie('monster');
Firefox 告诉我该 cookie 有确实已经设定了。值为big
,路径为/sesame/
。然而,当我尝试读取 cookie 时,它不起作用。
问题的替代版本:读取 cookie 时如何指定路径?
作为一项实验,我使用了以下语法,但它设置一个 cookie 而不是读取一个。
$.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/' });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JQuery cookie 扩展搜索
document.cookie
属性来查找 cookie 并读取其值。Document.cookie
将仅返回当前文档路径下 cookie 的名称、值对。不过,它确实允许您为与当前文档路径不同的路径设置 cookie。因此,这不是 jQuery cookie 插件的限制/错误;相反,它是 Javascript 处理 cookie 的副产品。
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.
浏览器不会将cookie发送到未设置的路径!
浏览器仅发送 cookie 名称和值。没有办法找出 cookie 路径或过期时间。
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.