[英]I can't get cookies using $cookies.get('key') of AngularJS
JavaScript代码
$cookies.put('test', 'test_value');
console.log('cookie value: ' + $cookies.get('test'));
我直接双击html文件,通过file:/// C:/Users/xxxxx/test.html访问它,但我发现它无法写入或读取cookie:
cookie值:未定义
如果我把html文件放到Nginx的'HTML'文件夹中并通过http://127.0.0.1/test.html访问它,我可以正常读取cookie:
cookie值:test_value
我不知道为什么,想知道解释。 谢谢。
如果您通过file://加载页面,大多数浏览器都不允许您与Cookie进行交互,则需要从本地Web服务器提供页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.