Can't access a cookie using document.cookie in JS

回眸只為那壹抹淺笑 提交于 2021-02-10 22:18:52

问题


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.

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.

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.

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

Thanks in advance for all your help!


回答1:


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.

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



来源:https://stackoverflow.com/questions/6217795/cant-access-a-cookie-using-document-cookie-in-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!