I've hot a very simple form in HTML, that sends GET information to my Node.JS server, with Express. This is the form:
<form method="get" action="/search" autocomplete="off" class="navbar-search pull-left">
<input name="search" type="text" id="search" data-provide="typeahead" placeholder="Search..." />
</form>
And this is the server part:
app.get('/search', function (req, res){
console.log(req.query["search"]);
res.render('search.ejs')
});
When I write something to the input, and press enter, and the page keeps loading for a long while, and I receive a 340 error when I get in for example in http://localhost:8080/search?search=foo. I think I have a problem with the from, that doesn't send properly the values, because it doesn't work with POSTrequest too. Any solution for this?
Thank's advance!
It is because you have to use the req.params.search instead of req.query which does not work.
app.get('/search', function (req, res){
var search = req.query.search;
console.log(search);
res.render('search.ejs')
});
Here you can read more about it: http://expressjs.com/api.html#req.param
Next time to figure out an erorr, type in app.get(... console.log(res, req); and find where your variables are.