Working with jquery post request node js response

I am trying to send a jquery post request to node js.
I have a form, whose button has a click event listener and sends a jquery post request to the route “/login” and also attaches the data entered in the input fields. The node js works fine, but all the activities being done when the node js server gives some response back do not work. Here’s my javascript:

const loginCont = document.getElementById("loginCont");

loginCont.addEventListener("click", () => {
    const loginError = document.getElementById("login_error_box");
    const loginUser = document.getElementById("loginUsername").value;
    const loginPass = document.getElementById("loginPassword").value;

    $.post('/login',
        { username: loginUser, password: loginPass },
        function(data, status, jqXHR) { // Anything I do in this function doesn't get executed.
            loginError.classList.remove("hidden");
            loginError.innerHTML += `Login success`;
        }
    );
});

And here’s my server-side code (node js) :

var express = require('express');
var app = express();
var fs = require('fs');
var MongoClient = require('mongodb').MongoClient;
var bodyParser = require('body-parser')
app. use( bodyParser.json() );
app.use(bodyParser.urlencoded({ extended: true })); 

app.post('/login', function (req, res) {
  var user = req.body.username;
      pass = req.body.password;

  var myobj = { "user": user, "pass": pass };

  MongoClient.connect(mongo_profiles_url).then(function(db, err) {
    if (err) throw err;

    var dbo = db.db("PAL");
    dbo.collection("user-profiles").find(myobj).toArray(function(err, ob) {
      if (err) throw err;

      if (ob.length == 1) {
        var r = "success"
        res.writeHead(200, {'Content-Type': 'text'});
        console.log(` A person is trying to login with the following details (and is successful in doing so):
        • Username : ${user}
        • Password : ${pass}
        `);
      } else {
        var r = "fail"
        res.writeHead(200, {'Content-Type': 'text'});
        console.log(` A person is trying to login with the following details (but failed to do so):
        • Username : ${user}
        • Password : ${pass}
        `);
      }
      res.end(r);
    });
  });
});

app.listen(1000, function () {
    console.log("Server listening to http://localhost:1000");
});

Hope someone or the other will be able to help me out.

Thanks in advance!