php - 在 Internet Explorer 9 上的子目录无法访问的根路径 (/) 上使用 jQuery 设置 Cookie

标签 php jquery internet-explorer cookies path

我使用以下代码在根目录上使用 jQuery 设置 cookie:

$.cookie('key', 'value', {
    path: '/',
    expires: 30
});

然后我在整个网站上读取 cookie,但 IE9 只会在主页 (www.example.com/) 上找到 cookie,而不会在其他页面 (www.example .com/subdirwww.example.com/subdir/sub)。

事实上,当我在任何子目录页面上 var_dump($_COOKIE) 时,我得到的只是 array(0) {}

我可以通过缓存->查看cookie信息来查看cookie。它在那里并设置为 /

在所有其他浏览器中完美运行。

最佳答案

设置您的cookie如下:

$.cookie('key', 'value', { path: '/', domain: 'example.com', expires: 30 });

欲了解更多信息,请查看Cookies and domains

希望这对您有帮助。

关于php - 在 Internet Explorer 9 上的子目录无法访问的根路径 (/) 上使用 jQuery 设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464936/

相关文章:

javascript - 使用文本和.innerHTML插入元素是否错误?

html - 两个 float 的 div,一个在下面。适用于除 IE 之外的所有浏览器

html - Internet Explorer 8 DOCTYPE 被忽略/评论

javascript - 在 JavaScript 中创建列表项

php - 检查用户名和密码后重定向 ajax 调用

javascript - jquery删除除第二个选项值外的 'select option'元素值

php - PHP 中单引号和双引号字符串有什么区别?

php - 哪个 PHP 函数使用了这种哈希算法?

php - mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows 等...期望参数 1 是资源

php - 为什么 PHP 会抛出这个解析错误?