为了账号安全,请及时绑定邮箱和手机立即绑定

PUT 请求不运行 Knex 更新语法并且不抛出任何错误,在 POSTMAN 中继续加载。

PUT 请求不运行 Knex 更新语法并且不抛出任何错误,在 POSTMAN 中继续加载。

至尊宝的传说 2021-11-25 15:41:00
After creating an endpoint that handles a PUT request, I followed the knex documentationto update the record in the database, the result I get when I test using POSTMAN is:it keeps loading forever, I don't get any error or message in the terminal. But when I console.log(req.body) it shows in the terminal the JSON sent from POSTMAN is hitting the endpoint and I can see the data. I created other endpoints for GET requests using knex > documentation and it is working fine except for the PUT method. I have attached 3 images; the first shows how POSTMAN keeps loading forever, and thesecond shows the data I sent from POSTMAN being logged in theterminal. And the code showing the endpoint and knex syntax.我想让 knex 更新与记录的 id 与其接收的数据相匹配的记录。
查看完整描述

1 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

我犯了一些语法错误。


app.put('/update', (req, res) => {

    // console.log(req.body)

    const { id, name, year, house, mobile, email, occupation, gender} = req.body

    db.select('*')

        .from('unity_gate')

        .where('id', '=', id)

        .update({name: name, year: year, house: house, mobile: mobile, occupation: occupation,

            gender: gender, email: email})

        .then(data => res.status(200).json('Success'))

        .catch(err => console.log('Error', err));

})


查看完整回答
反对 回复 2021-11-25
  • 1 回答
  • 0 关注
  • 133 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信