jQuery: Set cookie on one page and retrieve from another -
i have 2 html pages.
setcookie.html
:
<script> if($.cookie('order_by') == null){ $.cookie('order_by', 'name'); } console.log($.cookie('order_by')) //works fine </script>
now, want retrieve cookie on other page not able do. now, there link in setcookie.html
takes me getcookie.html
.
getcookie.html
:
<script> console.log($.cookie('order_by')) //doesn't work </script>
as cookie set(and it's never expiring), should able retrieve value on other page. right?
how can so?
edit:
this whole html of getcookie.html
.
<ul class="filter-by"> <li> filter by<br /><script>$('.filter-by li').append('<strong>'+$.cookie('order_by' , { path: '/' })+'</strong>');</script> <ul class="filter-items-list"> <li>name</li> <li>views</li> <li>latest</li> <li>downloads</li> </ul> <script> $('.filter-items-list li').click(function(e) { $.cookie('order_by',$(this).html(), { path: '/' }); location.reload(); }); </script> </li> </ul>
i think see problem. need set cookie whole site:
setcookie.html:
$.cookie('order_by', 'name', {'path': '/'});
getcookie.html:
console.log($.cookie('order_by'));
Comments
Post a Comment