繁体   English   中英

在 react.js 和 express.js 中注册?

[英]Register in react.js and express.js?

我在 react.js 中做第一个注册框,并在后端使用 node.js, expres.js。 我使用 fetch 来发布用户名、密码、ID,但它不起作用。 你能找出我的错误吗?

  const [usernameReg,setUsernameReg] = useState('')
  const [IDdReg,setIDReg] = useState('')
  const [passwordReg,setPasswordReg] = useState('')

  const register = () => {
    fetch(`http://localhost:3001/api/post/register${usernameReg}${passwordReg}${IDdReg}`)
    .then(res => res.json())
    .then(json => console.log(json))
  }
app.post('/api/post/register:username/password/Id', (req,res) => {
    const username = req.params.username;
    const Id = req.params.Id;
    const password = req.params.password;
    const sqlSelect = `INSERT INTO can_bo VALUES (?,?,?)`
    db.query(sqlSelect, [username, password, Id], (err,result) => {
          console.log(err);
    })
})

我认为,在您的 fetch 参数中,将用“/”相互分隔。 像这样。 ...

获取( http://localhost:3001/api/post/register${usernameReg}/${passwordReg}/${IDdReg}

...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM