Cookie在页面刷新时消失 [英] Cookie disappears on page refresh

查看:811
本文介绍了Cookie在页面刷新时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery.cookie设置cookie,但是,如果刷新页面或打开新页面,有时cookie会丢失.为什么会这样?

I'm using jQuery.cookie set cookies, however if I refresh the page or open a new page,sometimes, the cookie is lost. Why is this happening?

这是我的代码:

jQuery.cookie('sid', 'sessionid', {expires: 30, path: '/', domain: 'xici.net'});

讨论: 到期:30表示30天,由jQuery.cookie库的cursse代码设置.

discussion: expires: 30 means 30 days, it set by jQuery.cookie library scurse code.

推荐答案

在当前时间上添加该30分钟的值,以指定该cookie在以后的 30分钟内退出.

Add that 30 min value to the current time to specify that exipre this cookie in 30 minutes in the future.

var date = new Date();
date.setTime(date.getTime() + (30 * 60 * 60 * 1000));
var myCookieValue = $.cookie('myCookie');
jQuery.cookie('myCookie', null);
jQuery.cookie('sid', 'sessionid', {expires: date, path: '/', domain: 'xici.net'});

这篇关于Cookie在页面刷新时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆