Home > Software engineering >  Hi everyone, how can I refresh the page without reloading it?
Hi everyone, how can I refresh the page without reloading it?

Time:08-21

I am building a project using NodeJS, ExpressJs and ejs. Let's say that I have a button that submits the form the real problem is that when I submit the form an element of the page (a variablie ejs) must change so I have to reload the page: there is a way not to have to reload the whole page, but maybe just that element? Or, in any case, it is also fine to reload the whole page but without the user having to see that the url is reloading

CodePudding user response:

You can use Angular JS, the feedback loop helps updating the variable/element if it changed in the backend(modal) and vice-versa.

CodePudding user response:

To prevent default behaviour when the form is submitted - and that is reloading the page you need to use Event.preventDefault(), here is more on it: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault; and change your variable with javaScript - this will be the page refresh without reloading.

Your code should look sth like this:

const handleFormSubmit= (event)=> {
    event.preventDefault();
    more code here... }
  • Related