-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Express + EJS Template] Reload part of HTML rendered page with new elements #774
Comments
In order to resolve this issue, update only a part of the webpage without reloading the whole, use AJAX techniques with Fetch API or Axios. You will get the data from your server and update just one portion of your HTML, such as a table, while all the rest remains unchanged on your page. |
Do you have any suggestions on how to structure the JavaScript code for the client-side inside the project folders? Are there some best practices on that? |
Hi! As @Harshit-Maurya838 writes, you should use AJAX request to send a get request to the server and the server should respond by sending rendered EJS template, then you need your code to swap an existing element with the new one sent by the server. I can highly recommend HTMX library for this as it makes these AJAX requests as simple as writing one or two HTML attributes. Look up "Net Ninja" on Youtube for nice step by step tutorials on it. |
Hi everyone,
I'm new in web development with Node.js, and I would like to know what is the best way to reload part of rendered HTML page, when I retrieve other information from a database (e.g when perform a fetch with a GET request to retrieve a JSON list of object to visualize in a table).
Are there some best practices in Express or in EJS to handle this kind of behavior?
Thanks in advance!
The text was updated successfully, but these errors were encountered: