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.
Here's my code:
$.cookie('testcookie',1,{expires: 5, path:'/'});
console.log($.cookie('testcookie'));
var variable=$.cookie('testcookie');
console.log(variable);
That function should log '1' in the console twice, but just gives me two instances of undefined
.
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.
See: Why does Chrome ignore local jQuery cookies?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With