我创建了一个变量来从我的前端捕获数据,并希望在我的 Express 后端检索它。
我的 js 变量和 POST 请求:
const dataPush = {
urlSave: urlSave,
imgSave: imgSave,
marqueSave: marqueSave,
smSave: smSave,
typeSave: typeSave,
precisionSave: precisionSave,
yearsSave: yearsSave,
coteEuSave: coteEuSave,
coteUsdSave: coteUsdSave,
coteGbSave: coteGbSave,
coteChfSave: coteChfSave
}
let postIdUrl = String('/fr/post')
fetch(postIdUrl, {
method: "POST",
body: JSON.stringify({"data": "dataPush"}),
headers: { "Content-Type": "application/x-www-form-urlencoded" }
})
console.log(dataPush)
没关系,我得到了我需要的所有数据。
我的快递代码:
router.post('/post', (req, res) => {
console.log('yep !')
});
如何从dataPush变量中检索数据?