-2

thanks for answers, question needed some more code examples to be resolved

Magdi T.
  • 1
  • 2

2 Answers2

0

You can replace the default submit button behaviour with your own function like this or even just don't use <form> at all and use on click listener on a normal button.

In that function you can then send the data to your backend yourself by using an XmlHttpRequest, example and documentation.

SomeCoder
  • 275
  • 1
  • 19
0

This is a matter of which page you will be directed to and which ejs structure you will use. If you call the same page after the post process, you will call a page that uses that api. This causes the data you previously posted to be sent again. Instead, if you return to the first submitted api url source of the form, you can both re-render the page and prevent the form data from being resubmitted.

If you use this in the same api after post processing, it will cause you to send the data again:

res.render("index.ejs"); 

try returning to the first page source instead:

res.redirect("/")

I hope it was understandable.