Below is the Form component of my webpage
<form action="/login" method="POST">
<h3>Traditional Form</h3>
<div class="form-row">
<label for="name"> enter name </label>
<input type="text" name="name" id="name" autocomplete="false" />
</div>
<button type="submit" class="block">submit</button>
</form>
And this is the api handling POST request
const express = require('express');
let app = express()
app.use(express.static("./methods-public")) // storing html file
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.post('/login', (req, res) => {
if (req.body.name)
return res.status(200).send(`we go the person ${req.body.name}`)
res.status(401).send("Wrong user")
})
app.listen(2600, () => console.log("We are listening"))
Now this is just the beginning , but what I am observing is that whenever I try to submit any data, I am led to the webpage localhost:2600/login
. Now I realize that upon submitting the form , the data is sent to POST method for /login
to handle , but it is a POST method. Why and how am I redirected to localhost:2600/login
by an POST method ?
I want to know WHY & HOW it redirects use to new webpage. What happens at the backend in the logic that it redirects use to new webpageCan anyone please explain how any why is it happening so ? Thank You