访问/delcookie路由时浏览器挂起? [英] Browser hangs when accessing /delcookie route?
本文介绍了访问/delcookie路由时浏览器挂起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够设置和打印cookie对象,但是当我访问 delcookie
路由时,浏览器将挂起并且不会删除cookie.
I am able to set and print the cookie object but when I access the delcookie
route, my browser hangs and does not delete the cookie.
我的语法对delcookie路由是否正确?
Is my syntax correct for the delcookie route?
var express = require ("express");
var app = express();
app.use( express.cookieParser() );
app.get('/setcookie', function(req, res){
res.cookie('cookiename', 'cookievalue', { maxAge: 900000, httpOnly: true });
res.send ('200', "<div style='font-weight:bold; color:blue'>setting cookie</div>");
console.log (req.cookies);
});
app.get('/printcookie', function(req, res){
res.send ('200', "<div style='font-weight:bold;'>printing cookie</div>");
console.log (req.cookies);
});
app.get('/delcookie', function(req, res){
res.clearCookie('cookiename', { path: '/setcookie' });
});
app.listen(1337);
推荐答案
您实际上不是在发送响应. sendCookie
方法告诉Express添加一个标头,该标头将在发送响应后删除cookie.
You aren't actually sending a response. The sendCookie
method tells Express to add a header that will delete the cookie when the response is sent.
添加确实会发送响应的内容:
Add something that does send a response:
app.get('/delcookie', function(req, res){
res.clearCookie('cookiename', { path: '/setcookie' });
res.send('ok');
});
这篇关于访问/delcookie路由时浏览器挂起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文