I have a form in a modal window, which makes a POST to an API on the server, and then the server saves the information in the DB. The server is made with Node Js and express. The problem is that when doing the submit, the IP address of the API is opened, and what I need is that the main page of my application is reloaded. Also, how do I capture the response from the server if the operation was successful or there was an error ... here the frontend code:
<form action = {apiUrl} method = "POST">
<div className = "booking-checkOut">
<label >Check Out: </label>
<input type = "date" min = {minDate} name = "checkOut" required />
</div>
<div className = "booking-pasajero">
<input name = "idPasajero" placeholder = "Nro identificacion" />
<input name = "pasajero" placeholder = "pasajero" required/>
<input type="email" placeholder ="email" />
<input name = "nacionalidad" placeholder = "nacionalidad" />
</div>
<div className = "booking-booking">
<p>Datos de la Reserva</p>
<input type = "number" name = "cantPas" placeholder = "Cantidad de Pasajeros" min = "1" required/>
<input type = "number" name = "tarifa" placeholder = "tarifa" step = "0.01" min = "10" required/>
<textarea name = "observ" placeholder = "Observaciones"></textarea>
</div>
<input type = "hidden" name = "room" value = {props.data.roomNumb} />
<input type = "hidden" name = "checkIn" value = {props.data.checkIn} />
<input type = "hidden" name = "habitacionId" value = {props.data.roomID} />
<button type = "submit" className = "modal-btn primary">Confirmar</button>
</form>
<button
className = "Modal-close"
onClick={props.clickCerrar}
></button>
and on the server I have this route:
app.post('${API_BASE}/new-booking', (req, res) => {
data(req.body)
.then (pgdata => {
res.send("ok")
})
.catch(err => console.log(err))
}
that receives the data of the form and with the data function saves it in the database.
Greetings