I have set some values in cookie but I can’t received the cookie data to another page on my web page. It display me error undefined variable , but same variable work in the same page, problem only another page.
How can I get cookie data another page using jQuery.
My code is:
<script type="text/javascript"> function add_to_cart(id){ $.cookie('p_id', id); } </script>
Set path in your cookie data and get cookie value from any page. For example
If cookie reslt first time blank or undefined then follow this example code:
<script type="text/javascript"> function add_to_cart(id){ if($.cookie("p_id")=="" || $.cookie("p_id")==undefined){ $.cookie('p_id', id, { path: '/' }); } } </script>
If your want to set expires date in cookie data then follow this code:
<script type="text/javascript"> function add_to_cart(id){ $.cookie('p_id', id, { expires: 7, path: '/' }); } </script>
Question and answer is powered by AnsPress.io