0
I have a form where I send requests POST pro nodejs save in the database but when I send the information it is redirected to the route and I receive the res
{"fieldCount":0,"affectedRows":1,"insertId":7,"serverStatus":2,"warningCount":0,"message":"","protocol41":true,"changedRows":0}
Only that I need it to continue on the form page and just send an alert to the user saying that it was successfully registered, as I do it?
router.post("/reportar", (req, res) => {
const latitude = req.body.latitude.substring(0, 10);
const longitude = req.body.longitude.substring(0, 11);
const descricao = req.body.longitude.substring(0, 700);
execSQLQuery(
`INSERT INTO erros (latitude, longitude, descricao) VALUES ('${latitude}','${longitude}','${descricao}')`,res);
});
<form id="contacts" autocorrect="off" name="adicionar" autocomplete="off" method="post" action="http://192.168.0.30:3000/reportar">
<input id="valorlat" type="text" name="latitude" value="">
<input id="valorlong" type="text" name="longitude" value="">
<textarea class="input-field" class="textarea1" name="descricao">
<button type="submit"> Enviar </button>
</form>
function mySubmitFunction(e) {
e.preventDefault();
$.ajax({
url:"http://192.168.0.30:3000/reportar",
success: function(response){
alert("Banheiro adicionado com sucesso")
}
});
return false;
}
Sorry, I didn’t get it very well. You have an HTML form and a Submit button?
– G. Bittencourt
this, only when I click on Ubmit he enters this screen, and I wanted him to be on the form screen
– Lucas Martins
Could you please put the HTML part of the form code and the method that is called when submitting the form?
– G. Bittencourt
Basically, just indicate that the default behavior is not executed, but to explain better I need to know how the structure of your form is.
– G. Bittencourt
I updated my form. It sends and does everything right, only instead of it redirecting to the page that shows that first line of code, I want it to be on the form page but a warning to the user that it was successfully registered or that there was a problem when registering, but without redirecting to another page
– Lucas Martins