簡體   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