我不知道這是否足以發布代碼,但這是導致我的錯誤的行:(res.redirect)行
app.post("/home/finishform",urlencodedParser, (req,res)=>{
const score = new Score(req.body)
score.save()
.then((result)=>{
res.redirect("/")
}).catch((err)=>{
console.log(err)
})
res.redirect("/home/FinishPage/client")// This is causing the error, but it's actually redirecting, so it's working but I keep getting an error.
})
uj5u.com熱心網友回復:
您有兩次呼叫redirect,這會導致錯誤。如果保存成功,您可能應該只重定向:
app.post("/home/finishform",urlencodedParser, (req,res)=>{
const score = new Score(req.body)
score.save()
.then((result)=>{
res.redirect("/home/FinishPage/client") // Here!
}).catch((err)=>{
console.log(err)
})
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/503953.html
上一篇:路由器中的中間件顯示req.body為空,但實際資料確實存在于post請求中
下一篇:錯誤[ERR_HTTP_HEADERS_SENT]:在將標頭發送到客戶端后無法設定標頭在nodejs中使用重定向時發生錯誤
