如何在注销按钮上删除cookie

How to remove a cookie on logout button?

本文关键字:删除 cookie 按钮 注销      更新时间:2023-09-26

单击注销按钮时,我很难删除cookie。我现在有一个注销按钮和类注销。这是我试图放入的删除cookie的简单jquery行,但它不起作用。

$('button .logout').click(function () {
            $.cookie('userid', null);
       };

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);
};

使用一个简单的express-node js cookieParser,里面有一个秘密。

给它负时间,只需将值设置为零。

嗯,试试:

$('button .logout').click(function () {
    $.cookie('userid', "", -1);
});