我像這樣從 js 檔案設定發布請求:
fetch('/account/signup', {
method: 'POST',
body: JSON.stringify({ username: document.getElementById('username').value, password: document.getElementById('password').value, email: document.getElementById('email').value, startingBal: document.getElementById('startingBal').value })
}).then(response => response.json());
}
我有一個路由器接收發布請求
const router = express.Router()
router.use(bodyParser.urlencoded({ extended: true }))
router.use(bodyParser.json())
router.post('/signup', (req, res) => {
console.log(req.body)
})
然而它只將 {} 記錄到控制臺,因此它接收請求但不記錄任何內容。
uj5u.com熱心網友回復:
在您的獲取配置中添加標頭:
內容型別:應用程式/json
如果它不起作用,請使用郵遞員并分享結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/536442.html
標籤:节点.js表示要求
