Search code examples
javascriptjquerycookiesjquery-cookie

Cannot set cookie with jQuery Cookie


I'm using jQuery Cookie 1.4.1. Here's my code:

<!DOCTYPE html>
<html lang="en">
  <head>
  </head>
  <body>
    <a href="#" onclick="test()">test</a>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="jquery.cookie.js"></script>
    <script>
      function test() {
        $.cookie('name', 'value');
        console.log($.cookie('name'));
      }
    </script>
  </body>
</html>

The console shows "undefined"

Could anyone help me?


Solution

  • I'm developing on localhost. It seems that Chrome ignores local jQuery cookies:

    Why does Chrome ignore local jQuery cookies?