I'm currently practicing my skills in node.js with a movie app project and I'm stuck with this (I hope) small problem.
I have a search input element on the homepage that would accept a movie title. After pressing the submit button I would like to redirect to a search page with the results.
This is the code in my js file on the client side:
$(function () {
$('button').click(function (event) {
// the value people enter in the search box
var search = $('.searchInput').val();
//replace spaces with _
var res = search.replace(/\s/, "_");
// redirect to trigger GET in indexjs with specific search value
window.location.replace("localhost:4000/search/" + res);
});
});
And I would like to trigger this GET in my index.js (server side) file to start firing an ejs file specific to the search value.
router.get('/search/:id', function (req, res, next) {
console.log('entered')
var name = req.params.id
res.render('search', {
name:name});
});
The window.location.replace function unfortunately isn't working though. Can anyone see what the problem is?