你好,我在節點 JS 中使用 express 模塊
res.json({ auth: true, token: token, message: "success" });
res.redirect('/');
我必須先發送一些 json 資料然后重定向..但我收到此錯誤:
node:_http_outgoing:576
拋出新的 ERR_HTTP_HEADERS_SENT('set'); ^
錯誤 [ERR_HTTP_HEADERS_SENT]: 發送到客戶端后無法設定標頭,
誰能幫忙,謝謝
uj5u.com熱心網友回復:
您可以將“重定向”作為屬性包含在 json 中,例如:
res.json({ auth: true, token: token, message: "success", redirect : "/whatever/go"});
然后,在客戶端,您可以像這樣執行重定向:
fetch(url)
.then(res => res.json())
.then(body => window.location.href = body.redirect)
.catch(err => console.log(err));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/439977.html
標籤:javascript 节点.js 表示
上一篇:Shadowroot:沒有為事件偵聽器獲取正確的目標
下一篇:無法使用反應顯示其他值
