无法在JS中使用document.cookie访问cookie [英] Can't access a cookie using document.cookie in JS

查看:124
本文介绍了无法在JS中使用document.cookie访问cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题.我正在构建一个与Drupal Services接口的外部移动Web应用程序.当我调用login.json服务时,会设置一个cookie(或我认为),该cookie告诉Drupal我已登录.

I'm running into a weird problem. I'm building an external mobile webapp that intefaces with Drupal Services. When I call the login.json service, a cookie is set (or so I think) that tells Drupal that I'm logged in.

该Webapp当前正在同一域下但在子目录中运行.但这是棘手的部分.在我的chrome资源浏览器中,我可以在cookie下看到该cookie.但是,当我尝试记录document.cookie的内容时,它返回为空.

The webapp is currently running under the same domain but in a subdirectory. But here's the tricky part. In my chrome resources browser, I can see the cookie under cookies. However, when I try to log the contents of document.cookie it comes back empty.

我需要做的是检查我的JS代码中该cookie的存在.但是由于无法从document.cookie中获取它,因此我不确定自己缺少什么.

What I need to do is check for that cookie's existence in my JS code. But since I can't get it from document.cookie, I'm not sure what I'm missing.

此外,cookie的到期日期不早于今天,并且域匹配.

Also, the cookie's expiration date is not earlier than today, and the domain matches.

在此先感谢您的帮助!

推荐答案

类似cookie的声音是 HTTP仅.如果这是Drupal设置的,则在没有可用设置的情况下,可能必须修改Drupal源代码才能对其进行更改.

Sounds like the cookie is HTTP only. If this is set by Drupal, you may have to modify the Drupal source code to change it if there is no setting available.

票证指示从v6.x开始仅使用HTTP cookie,例如安全措施.

A ticket on the Drupal tracker indicates that HTTP only cookies are used starting from v6.x, as a security measure.

这篇关于无法在JS中使用document.cookie访问cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆