【发布时间】:2009-01-28 21:06:12
【问题描述】:
我正在使用 jQuery 插件来设置 cookie,当我使用 localhost 作为域时,它不会存储 cookie。
这是我在 jQuery 1.2.6 中使用的插件。
http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
以下是我正在使用的代码。您可以看到它不喜欢 localhost,我是从 localhost 上的开发 Web 服务器运行它。一个细节是我正在运行端口 4005,但这不应该影响域,AFAIK。
$(function() {
console.log('Testing');
var one = $.cookie('Test.One');
var two = $.cookie('Test.Two');
var three = $.cookie('Test.Three');
console.log(['one', one]);
console.log(['two', two]);
console.log(['three', three]);
$('#div1').text(one);
$('#div2').text(two);
$('#div3').text(three);
$.cookie('Test.One', 'Test 1');
$.cookie('Test.Two', 'Test 2', { path: '/' });
$.cookie('Test.Three', 'Test 3', { path: '/', domain: 'localhost' });
});
【问题讨论】:
标签: javascript jquery cookies