4

Hello I'm stuck with a situation and I'm not capable to get JS-Cookie v2.1.3 working as expected. I'm thinking that there is some browser issues involved on this point, but I can't determine it exactly so I wish someboduy could give some light My goal is to set up a language cookie on my site, I have the following code:

 jQuery(document).ready(function($) {

    $('#botEn').click(function(e) {
      Cookies.set('idioma', 'en', {
        expires: 7,
        path: '/'
      });
      $('.alert').html('<p>Btn english >> cookie:'+Cookies.get('idioma')+'</p>');

    });

    $('#botEs').click(function(e) {
      Cookies.set('idioma', 'es', {
        expires: 7,
        path: '/'
      });
      $('.alert').html('<p>Btn español >> cookie:'+Cookies.get('idioma')+'</p>');
    });

});

https://jsfiddle.net/faridsilva/vrqvLfk2/18/

Mi fiddle showing the issue

This code only works in chrome (my version is 56.0.2924.87 64-bit), but firefox 51.x and safari 10.x always returns "undefined"

The same happens to me with Dustin Simpson example in his fiddle which he says is working fine as reply to this question.

Dustin Simpson fiddle

Community
  • 1
  • 1
  • I came across this answer is my search for solution to scenario where `Cookies.get()` was always returning `undefined` - if it helps anyone, I was developing locally and I don't think Cookies works in local environment, on live site it works as expected. See: https://github.com/js-cookie/js-cookie/issues/281 – user1063287 Oct 09 '17 at 01:00
  • 1
    I my case the reason why i couldnt access the cookie was that it was created on server and was secure. Since i could not read the cookie value, i needed to do the logic at serverside and pass the information i needed not via cookie. – Tim Schmelter Nov 19 '20 at 08:32

0 Answers0