Lio*_*789 5 javascript cookies jquery
单击注销按钮时,我很难删除 cookie。我目前有一个带有类注销的注销按钮。这是我试图删除cookie的简单jquery行,但它不起作用。
$('button .logout').click(function () {
$.cookie('userid', null);
};
Run Code Online (Sandbox Code Playgroud)
userid 是 cookie 的名称。
哦,我正在使用签名 cookie,不确定这是否会改变什么?
编辑:
这是我设置cookie的方法:
exports.loginPost = function(req, res, next) {
console.log("here 1");
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
if (!user) {
return res.render('loginError', {title: 'Weblio'}); }
req.logIn(user, function(err) {
if (err) { return next(err); }
console.log(JSON.stringify(user));
res.cookie('userid', user._id, { maxAge: 900000, signed: true });
res.redirect('userProfile');
});
})(req, res, next);
};
Run Code Online (Sandbox Code Playgroud)
并使用一个简单的 express - node js cookieParser,其中包含一个秘密。
给它负时间并将该值设置为空。
嗯,尝试一下:
$('button .logout').click(function () {
$.cookie('userid', "", -1);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13933 次 |
| 最近记录: |