JavaScript 代码
$cookies.put('test', 'test_value');
console.log('cookie value: ' + $cookies.get('test'));
我直接双击html文件通过file:///C:/Users/xxxxx/test.html访问它但我发现它无法写入或读取cookie:
cookie value: undefined
如果我将html文件放入Nginx的'HTML'文件夹中并通过http://127.0.0.1/test.html访问它,我可以正常读取cookie:
cookie value: test_value
我不知道为什么,想知道一个解释。谢谢。
最佳答案
如果您通过 file://加载页面,大多数浏览器不会让您与 cookie 交互,您需要从本地网络服务器提供该页面。
关于javascript - 我无法使用 AngularJS 的 $cookies.get ('key' ) 获取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44732460/