jquerycookiesjs-cookie

js-cookie always get undefined when Cookies.get


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).


Solution

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