I'm trying to get the value of the query string term=+ e.target.value
in the server but it's not showing up. Tried to write the route as '/doSomeSearch?term' and still no req.query.term doesn't show any value in the server.
I changed the header from json to 'Content-Type': 'application/x-www-form-urlencoded' but only get 404 error back. Is the route not correct?
Input.js
handleInputBox (e) {
if(event.keyCode == 13){
event.preventDefault();
fetch('http://localhost:3000/searchItems?term='+ e.target.value, {
method: 'POST',
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
},
},
).then(response => {
if (response.ok) {
response.json().then(json => {
console.log("yes")
});
}else{
console.log("no")
}
}
);
}
};
Server.js(Express)
app.get('/doSomeSearch?', function (req, res) {
console.log(req.query)
})
some/path?termthe query parameter doesn't actually have a value.?"searchItems" !== "doSomeSearch"and?isn't actually part of the route. Give a minimal reproducible example. What's the actual URL you're hitting; is the problem that your frontend is generating the wrong URL (in which case the Express code is irrelevant) or your server has the wrong behaviour for the right URL (in which case the fetch is)?app.postor the method in fetch should beget?