-1

So, I've got a page where i set a cookie with js-cookie script and following code. js.cookie-2.1 is loaded right before that script.

 Cookies.set('dir', '1');

No JS errors there. When i try to get the cookie value on a different page, it looks like cookie script is not loading. Using following code

 jQuery(document).ready(function(){
    var cookie = $.cookie('dir');
       if (cookie > 1) { 
          $(".thereiscookie").show(); 
          } else { 
          $(".testcookie").show(); 
          }
 });

And i'm getting this error "Uncaught TypeError: Cannot read property 'cookie' of undefined". js-cookie script is also loaded right before the above code.

Arlindo
  • 13
  • 5
  • Possible duplicate of [How do I set/unset cookie with jQuery?](http://stackoverflow.com/questions/1458724/how-do-i-set-unset-cookie-with-jquery) – gaetanoM Apr 20 '17 at 18:36
  • looks like jquery isn't loading on that page where you are trying to get back your cookie, or your jquery is in noConflict mode, try jQuery.cookie('dir'); – Karthik Ganesan Apr 20 '17 at 18:37
  • Tried that. no good. And if jquery wasn't loading at all, i assume I'd get error a little earlier at "jQuery(document).ready(function(){" part – Arlindo Apr 20 '17 at 19:34

1 Answers1

-1

JS Cookie moved away from jquery dependency a long time ago, infact the jquery version is no longer maintained. The version you have is of the newer kind. To set and get cookies, you would now use:

 Cookies.set('dir', '1');
 Cookies.get('dir');  //values is 1 

There is no need to use jquery, its a standalone library.

Sasang
  • 1,261
  • 9
  • 10