您的位置:首页 > Web前端 > Node.js

Node Error : Cannot set headers after they are sent to the client

2020-02-02 16:13 1301 查看

Node Error : Cannot set headers after they are sent to the client

问题原因

在请求时 ,才会出现这种报错,一定是因为,浏览器请求一次之后,服务器后台返回了两次或以上的响应

解决办法

清理多余次数响应;每次响应后立马return掉函数

router.get('/',function(req,res,next){

Goods.find({},function(err,doc){
if(err){
res.json({
status:'1',
msg:err.message
});
}else{
res.json({
status:'0',
msg:'',
result:{
count:doc.length,
list:doc
}
})
}
})
})
  • 点赞 1
  • 收藏
  • 分享
  • 文章举报
drift_away_ 发布了8 篇原创文章 · 获赞 6 · 访问量 171 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: