【发布时间】:2019-05-31 12:06:34
【问题描述】:
拥有一个带有我自己的 expressjs api 后端的反应前端。 Express v. 4.16.0
在 react 前端使用 fetch 来获取数据就可以了。
fetch('/desResData')
.then(res => {....}
当我尝试使用请求发布一些数据时,我得到:“POST http://localhost:3000/desResData 404 (Not Found)” 代码:
fetch('/desResData',
{
method: 'POST',
body: { product: "test" }, // tried JSON.stringify as well
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}
)
.then(res => {....}
粗略地说,我可以从前端到后端进行静态通信,但我无法参数化我的请求。
ExpressJS:
router.get('/', async function (req, res, next) {
console.log(req.body) // tried with using req and without using it
findByProduct("product") // some async db operation // this part is working fine while fetching without any post parameters
.then(data => {
res.json()
})
【问题讨论】:
-
快递代码长什么样?
-
你的后端代码是什么?你用的是快递'
.post(...)?
标签: javascript node.js reactjs express