I use the jQuery cookie plugin for storing cookies, with the following code I can save a Cookie for 7 days, but it only saves it for the page its created on. I want the cookie to be available for the whole website.
$.cookie('basket',basket,{ expires: 7 });
I tried to set a path, but that didn't seem to work
$.cookie('basket',basket,{ expires: 7, path:'/' });
full code: this works fine, but it only saves the cookie for the current page
function add_to_basket(id,title){
if($.cookie('basket')){
basket=$.cookie('basket');
var basket_array = basket.split(',');
var index = jQuery.inArray(id,basket_array);
if(index > -1){
return false;
}else{
basket+=','+id;
$.cookie('basket',basket,{ expires: 7 });
}
}else{
basket=id;
console.log(basket);
$.cookie('basket',basket,{ expires: 7 });
}
basket? If it's an object you need to run it throughJSON.stringify()first so you can store a string.