Using jQuery cookies to maintain user states becomes more popular. However, i’ve recently found a problem where state didn’t appear to be persisting and on viewing the cookie information, using the web developer toolbar, i had multiple versions of the same cookie.
when a cookie is created, its path is set default to ‘/’ meaning that the cookie is valid throughout the whole domain
Cookies can also be set per directory and they’ll be valid for a certain set of pages.
Therefore, to overcome this problem, instead of a simple name, value pair:
$.cookie('the_cookie', 'the_value');
you need explicitly set the cookie’s path as "/"
$.cookie('the_cookie', 'the_value', { path: "/" });
Advertisements