[英]Not getting the value of query string in express
我正在尝试获取服务器中查询字符串term=+ e.target.value
的值,但未显示。 试图将路由写为'/doSomeSearch?term'
,但仍然没有req.query.term
在服务器中不显示任何值。 我将标头从json更改为“ Content-Type”:“ application / x-www-form-urlencoded”,但仅收到404错误。 路线不正确吗?
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(快递)
app.get('/doSomeSearch?', function (req, res) {
console.log(req.query)
})
路由应为POST方法。 当您命中POST方法类型api且您已配置GET方法时,express无法找到签名并返回404。
app.post('/doSomeSearch?', function (req, res) {
console.log(req.query)
})
这应该可以解决问题。 希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.