V
V
Vladimir2019-12-15 07:12:15
JavaScript
Vladimir, 2019-12-15 07:12:15

How to get a response after submitting a form?

<form class="authenticate" id="reg" action="/register" method="POST">
        <input type="text" name="nickname" id="nickname" value="nickname" onclick="this.value=''">
        <input type="email" name="email" id="email" value="e-mail" onclick="this.value=''">
        <input type="password" name="password" id="pass" value="password" onclick="this.value=''">
        <button type="submit" id="auth">Sign up</button>
      </form>

app.post('/register', (req,res) => {

  const { email,nickname,password } = req.body

  pool.query(`select * from players where nickname = '${nickname}'`, (err,r,f) => {
    if(r != '') res.send(123)
  })

})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2019-12-15
@HistoryART

To get a response, you need to submit the form not through the action attribute, but with the help of xmlhttprequest. Try submitting the form via fetch, on the form's submit event. Don't forget to call .preventDefault() on the submit event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question