'how to get the input value using express and AJAX. How to make it work?

I have two files app.js and test.ejs with code:

app.js

const express = require('express')
const app = express()
app.use(express.urlencoded({ extended: false }));
app.set('view engine', 'ejs')
app.get('/', function (req, res) {
  res.render('pages/test');    });
app.post("/", function (request, response) {
  console.log(`info - ${request.body.test}`);    });
app.listen(3000, console.log('port: 3000'))

test.ejs

...<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>...
...<input id="fn_test" name="test" onkeyup="showResult(this.value)" type="text" required /> ...
... <script>
            function showResult(str) {
                $.ajax({
                    url: "/",
                    method: "POST",
                    contentType: "application/json",
                    success: (result) => {  }
                });
            }
  ...</script>

Console response: info - undefined



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source