JavaScript Update part of HTML page using NODE.JS and EJS update part of html page,update only part of html

I have the following express app which just renders the sample.ejs page. On that page when I press the button the attached script changes the div text to "THIS IS FROM J QUERY. I want the same thing to happen but I want the data to be coming from a database. In my express app if I try to use res.render(); every time I click the button then it reloads the page which I don't want. So is there a way to achieve this without reloading page and only update part of page? I have searched stack overflow and the web but can't get an appropriate answer or maybe I just am unable to understand. I know this is a very basic thing to ask.

APP.js

var express = require('express');
var app = express();
app.use(express.static('public'));
app.use(express.static('./src/views'));
app.set('views', './src/views');
app.set('view engine' , 'ejs');

app.listen(3000 , (err)=>{console.log('Listening')});

app.get('/' , function(req , res) {
    res.render('sample' , {result_from_database: res.body} );   
});

sample.ejs

<!doctype html>
<html lang="en">
<head>
    <title>Sample HTML File</title>
</head>

<body>
    <div id="holder">
        WELCOME
    </div>
    <form>
        <button type="button" id="HButton"> HELLO </button>
    </form>
</body>

<script>
    $(document).ready(function () {
        var form = $("#holder");

        $("#HButton").on("click", function () {
            form.html("THIS IS FROM J QUERY");
        });
    });
</script>

<script src="/lib/jquery/dist/jquery.js"></script>

</html>

Now this is what I want to do

<!doctype html>
<html lang="en">
<head>
    <title>Sample HTML File</title>
</head>

<body>
    <div id="holder">
        <%= result_from_database %>
    </div>
    <form>
        <button type="button" id="HButton"> HELLO </button>
    </form>
</body>

<script>
    $(document).ready(function () {
        var my_div = $("#holder");
        $("#HButton").on("click", function () {

          /* Tell app.js that I clicked a button and then app.js
             query the database and using ejs or something else update the
             my_div inner html with the database result without
             reloading page */
        });
    });
</script>

<script src="/lib/jquery/dist/jquery.js"></script>

</html>

NOTE: I'm not asking how to query the database

-Thanks

Answer:1

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

  1. javascript node this

I have an array ['2530491','2530491','2530491','2530492'] the 2530491 is duplicated thrice, and I want to remove a single value of 2530491 from 3 of them, so the output would be like : ['2530491','...

I have an array ['2530491','2530491','2530491','2530492'] the 2530491 is duplicated thrice, and I want to remove a single value of 2530491 from 3 of them, so the output would be like : ['2530491','...

  1. javascript remove only one class
  2. javascript remove only leading spaces
  3. javascript remove only leading whitespace
  4. javascript remove only tag
  5. javascript remove read only

im new to selenium (and to html), and in the previous projects i used a bit of selenium when I wanted to select a dropdown value I just right click on the dropdown > "inspect element" and boom, i got ...

im new to selenium (and to html), and in the previous projects i used a bit of selenium when I wanted to select a dropdown value I just right click on the dropdown > "inspect element" and boom, i got ...

I'm making a discord bot, and I'm trying to make use of the createChannel function shown here in the documentation. For some reason, I am getting the following error: TypeError: bot.createChannel is ...

I'm making a discord bot, and I'm trying to make use of the createChannel function shown here in the documentation. For some reason, I am getting the following error: TypeError: bot.createChannel is ...

  1. discord make channel private
  2. discord make channel read only
  3. discord make channel invisible
  4. discord make channel hidden
  5. discord make channel public
  6. discord make channel
  7. make discord channel invite only
  8. discord make existing channel private
  9. discord make afk channel
  10. discord make announcement channel
  11. discord make voice channel invisible
  12. discord make welcome channel
  13. discord make text channel private
  14. discord make new channel
  15. discord make default channel
  16. discord make text channel invisible
  17. discord make mute channel
  18. discord how to make channel push to talk
  19. discord make a music channel
  20. how to make discord channel look good