I am using jQuery to access/set the cookies. I have planted a cookie named CookieNo1 at path /.
I planted this using the url localhost:8080/audi.
The cookie value is stored, which I checked manually on the firefox cookies. Now when I try to access the same cookie, using the url localhost:8080/audi/products using $.cookie('CookieNo1');
This doesn’t seem to retrieve the value of the cookie. It returns a null value. However when I try to write the cookie using the same localhost:8080/audi/products url, it overwrites the previous cookie value. Please help me with this issue.
All I need is $.cookie('CookieNo1') to return the previous cookie value instead of null.
Thanks in advance
You have to set the expiry date. Otherwise, the cookie is removed at the end of the session. In JQuery:
$("CookieNo1", "value", {expires: 7})(this cookie stays for 7 days).In JavaScript:
max-agesets the maximum lifetime of a cookie, in seconds.EDIT
Quote from comments:
Your issue is caused by
secure: true. This attribute requires the cookie to be transmitted over a secure connection (https). Remove thesecure: trueflag if you’re not using an encrypted connection.