My goal is to retrieve the value entered into the #pinCode input and send it through an ajax request to my server side so that I can utilize this value as a search parameter in my sequelize query.
Currently, I am able to access the value using req.query.loginID and successfully execute a query. However, when attempting to return an HTML page in response, the page remains unchanged.
The following code represents the browser-side JavaScript GET request:
$('#pinCode').keypress(function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode === 13) {
const pin = {
loginID: $('#pinCode').val().trim()
}
function loginwithID(p) {
$.get('/home', p, function() {
$('#pinCode').val('')
})
}
loginwithID(pin);
}
});
This snippet showcases the GET request on the server side along with the corresponding sequelize query:
app.get("/home", function (req, res) {
db.Employee.findAll(
{
where: {
loginID: req.query.loginID
}
}).then(function (data) {
res.send(homePage.render(memberPage.render(data)));
})
});
I also came across information suggesting a POST request could be used instead. Although unfamiliar with making such requests, I am open to exploring this option for simplicity.