我使用jQuery插件来设置cookie,当我使用域的本地主机时,它不会存储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' });
});
发布于 2009-01-28 21:11:04
我在设置cookie时也遇到过类似的问题。创建一个域名并将其作为127.0.0.1添加到您的主机文件中。然后在该域上运行web应用程序。
发布于 2009-01-28 21:29:00
发布于 2009-01-29 16:05:49
我更新了jQuery插件,当cookie是本地主机时,不会将域添加到cookie。这解决了我的问题,而不需要接触hosts文件。
var domain = (options.domain && options.domain !== 'localhost') ? '; domain=' + (options.domain) : '';
https://stackoverflow.com/questions/489369
复制相似问题