为什么我所有的jQuery饼干上升未定义? [英] Why are all my jQuery cookies turning up undefined?

查看:161
本文介绍了为什么我所有的jQuery饼干上升未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面的主体的末尾采用了jQuery,jQuery Cookie插件和我自己的Javascript(按顺序)。我无法掌握的是为什么我的cookie不会读取当我 console.log 的cookie,或当我分配到一个变量和 console.log 变量。此外,当我在Chrome中打开网页并查看资源> Cookie部分时,它显示我的网页没有创建任何Cookie。

I've sourced jQuery, the jQuery Cookie Plugin, and my own Javascript (in that order) at the end of the body of my page. What I'm unable to grasp is why my cookie won't read when I console.log the cookie, or when I assign it to a variable and console.log the variable. Also, when I open the page in Chrome and look through the Resources>Cookies section, it shows that my page has created no cookies.

此外,问题可能做我的操作对本地文件。它尚未托管。一切都只是坐在我的驱动器上,而不是在互联网上。

Also, the problem may have to do with my operating on the file locally. It isn't hosted yet. Everything is just sitting on my drive, not in the internet yet.

这里是我的代码:

$.cookie('testcookie',1,{expires: 5, path:'/'});
console.log($.cookie('testcookie'));
var variable=$.cookie('testcookie');
console.log(variable);

这个函数应该在控制台中记录两次, c $ c> undefined 。

That function should log '1' in the console twice, but just gives me two instances of undefined.

我已经检查我的HTML四次了,我100%确定我的脚本的来源指向正确的地方。我还确保该函数被正确调用等。我检查了所有可能的问题,但我只是找不到任何错误。

I've checked my HTML four times now, and I'm 100% sure the sources for my scripts are pointed to the correct place. I've also made sure the function is being called correctly, etc. I've checked all the probable problems, but I just can't find anything wrong. Am I missing something?

推荐答案

是的,这听起来像是因为它托管在本地。

Yeah, it sounds like it is because it's hosted locally.

请参阅: Chrome为什么忽略本地jQuery cookies?

这篇关于为什么我所有的jQuery饼干上升未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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