【发布时间】:2022-02-10 21:42:08
【问题描述】:
我在显示 JSON 响应时遇到错误。
我的代码在这里。
app.get('/api/:id/:uid?',(req,res)=>{//? mean optional parameter
console.log(req.params);// to get parameter in console
const id=req.params.id*1;
console.log(id);
const tour=tours.find(el=>el.id===id);
res.status(200).json({
"staus":"success",
"tours":tour
})
res.send("done");
})
显示Cannot set headers after they are sent to the client
【问题讨论】:
-
"showing cannot set header before they are sent to client" - 你到底是什么意思?您认为自己的行为不正确的确切症状是什么?
-
你不能同时使用
.json和.send。
标签: javascript node.js express