jQuery Cookie路径 [英] jQuery Cookie path
本文介绍了jQuery Cookie路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery cookie插件来存储cookie,使用以下代码我可以保存Cookie 7天,但它只保存它创建的页面。我想要整个网站都可以使用Cookie。
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:'/' });
完整代码:这个工作正常,但它只保存当前页面的cookie
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 });
}
推荐答案
有同样的问题。
$.cookie('basket', value, { path: '/' })
这是jquery cookie插件。它将默认为当前页面的路径。
This is an issue with the jquery cookie plugin. It will default to the path of the current page.
这篇关于jQuery Cookie路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文