jquery cookies / javascript cookies -


i'm have planned design jewelry website add cart option. still don't know how keep selected items on cart after refreshing page through jquery. if knew please provide step step example or tutorial.

you can use simple jquery method links php file adds product site cookies; when want view cart, explode cookie.

an example:

$(document).ready(function(){     $("#product").click(function(){         // want item id         var itemid = document.getelementbyid("productid").value;         $.get("/inc/addtocart.php", { item: itemid }, function(data){              document.getelementbyid("result-sec").innerhtml=data;         });    });             }); 

your php file this:

if(isset($_get['item'])){     $_cookie['cart_ids'] = $_cookie['cart_ids'] . '::' . $_get['item']; } 

to view cart items, simply:

$all_items = explode("::", $_cookie['cart_ids']); foreach($all_items $item):     echo $item . "<br />"; endforeach; 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -