尝试在表中创建新条目时网络中的待处理状态

时间:2019-08-01 19:55:48

标签: reactjs express jwt axios passport.js

尝试将新数据的配方添加到表“食谱”。

console.log(data)和console.log(req.body)为我提供了我输入并发送到后端的值,但是它没有将其写入表格和chrome控制台中的Network上,我正在等待处理状态

在后端index.js __

中创建配方
<TextField helperText="Enter the name of your recipe" label="name" onChange = {(event) => this.setState({name: event.target.value})}/>
<Button color="secondary" onClick={(event) => this.handleCreate(event)}>Submit Recipe</Button>

在前端Profile.js __

中创建配方
{{1}}

输入字段示例:

{{1}}

1 个答案:

答案 0 :(得分:0)

再说一次-我不知道它为什么挂起,但是我修复了CREATE配方INSERT语句。

在api / index.js中,这就是数据对象的外观。 如果您查看console.log(req.user)-您会注意到它正在发送ID,而不是req.user中的user_id-因此我们不得不说外键user_id是来自用户的ID。

const data = {
  user_id: req.user.id,
  recipe_name: req.body.name,
  recipe_meal: req.body.meal,
  recipe_author: req.body.author,
  recipe_description: req.body.description,
  recipe_ingredients: req.body.ingredients,
  recipe_preparation: req.body.preparation
}

还要更改此内容:

从::

db.query('SELECT * FROM recipes', (err, rows) => {

收件人::

db.query('SELECT * FROM recipes WHERE user_id = ? ', [req.user.user_id], (err, 
rows) => {

我还成功添加了页面重新加载(200)。

if (response.status === 200) {
          console.log("Post Success");
          window.location.reload();
        }
相关问题