我在这里很困惑。每当有get请求时我都可以编辑和读取cookie,但是如果我通过帖子编辑cookie,则不会保存:
// GET
exports.index = function(req, res) {
req.session.teststore = "This is set from a GET";
console.log('Reading from a cookie..... :::' , req.session.teststore);
res.render('index');
};
// Outputs: 'Reading from a cookie..... ::: , 'This is set from a GET'
exports.page2 = function(req, res) {
console.log('Reading from a cookie..... :::' , req.session.teststore);
res.render('page2');
res.end();
};
// Outputs: 'Reading from a cookie..... ::: , 'This is set from a GET'
//POST
exports.update = function (req,res) {
console.log('the value of this cookie is ::: ' , req.session.teststore);
req.session.teststore = "This is set from a POST";
console.log('the value of this cookie is ::: ' , req.session.teststore);};
res.send(200);
}
// Outputs:
the value of this cookie is ::: This is set from a GET
the value of this cookie is ::: This is set from a POST
//GET
exports.page3 = function(req, res) {
console.log('Reading from a cookie..... :::' , req.session.teststore);
res.render('page3');
res.end();
};
// Outputs: 'Reading from a cookie..... ::: , 'This is set from a GET'
我很困惑因为我希望第3页的GET请求看到cookie已更新。为了确认,cookie只在'/'索引请求中设置了一次,然后仅在Post请求中更改。
有什么想法吗?