0

I'm using js-cookie plugin, I'm setting a cookie and when I try to read it I get always undefined.

I began doing

Cookies.set('cookie', {
              "something": {
                "key1": value1,
                "key2": value2}
});

Cookies.getJSON('cookie');

and it returns undefined

So I tried something easier doing

Cookies.set('key', 'value');  <-- my request setting the cookie
"key=value; path=/"           <-- the response
Cookies.get('key');           <-- my request getting the cookie
undefined                     <-- the response

I see I'm setting the cookie, because in the response I see the cookie generated, but I can't read the cookie.

In chrome's developers tools --> resources --> cookies I can't see any cookie. I only see that by default cookies are disbled for local files.

I closed chrome and opened it again from cmd with "chrome.exe --enable-file-cookies" but I still get the same. No way to retrieve the information stored in the cookies.

I'm stuck with this very simple code :(

edit: if I try to retrieve all the cookies with Cookies.get() then I get a Object {} as there is no cookies. The wird thing is that when I create a new cookie with Cookies.set('name', 'value') I get back a line as the cookie is created (in console with the debug).

Alex
  • 1,230
  • 2
  • 24
  • 46
  • I was struggling with the same problem. The only solution I have found so far is to run server with `php -S localhost:9000` (Linux) in required folder and open file on `http://localhost:9000/file.html`. – kmaci Jan 14 '16 at 15:57
  • I was doing it correctly, the problem is in chrome. I finally used tinyweb and everything worked fine. It's crazy... – Alex Jan 15 '16 at 09:20

2 Answers2

0

I was doing it correctly, the problem is in chrome. I finally used tinyweb and everything worked fine. It's crazy...

Alex
  • 1,230
  • 2
  • 24
  • 46
0

If your Cookie key is 'HttpOnly' you cannot access it on web page due to sandbox security. Either You can set 'HttpOnly' to false on server side for js-cookies to access it on page. Or access cookie value in Controller.