Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Express Router GET request console.log显示未定义的请求参数_Javascript_Json_Node.js_Express - Fatal编程技术网

Javascript Express Router GET request console.log显示未定义的请求参数

Javascript Express Router GET request console.log显示未定义的请求参数,javascript,json,node.js,express,Javascript,Json,Node.js,Express,我一直在寻找一个相同的问题,因为我觉得这对我来说是一个非常简单的错误,但最接近我发现的是。我正在学习Node.JS,正在编写一个相对简单的端点来接收特定艺术家的get请求: router.get("/:artistID", (req, res) => { console.log(req.params); console.log(req.params.artistId); res.send(req.params); }) 我希望看到的是1),一个带有{artistID:“wha

我一直在寻找一个相同的问题,因为我觉得这对我来说是一个非常简单的错误,但最接近我发现的是。我正在学习Node.JS,正在编写一个相对简单的端点来接收特定艺术家的get请求:

router.get("/:artistID", (req, res) => {
  console.log(req.params);
  console.log(req.params.artistId);
  res.send(req.params);
})
我希望看到的是1),一个带有{artistID:“whatIsent”},2)一个“whatIsent”的JSON对象,然后3)当我使用API测试工具(如Postman)时,将同一个JSON对象作为响应

结果1)和3)按预期发生,但我在控制台中看到:

{ artistID: 'whatIsent' }
undefined
以下是我发送的GET请求:

到底发生了什么?Express是否将
artistId
转换为非字符串的中间对象


编辑:我使用了
typeof req.params.artistId
,它还返回未定义的…

您正在将变量定义为
artistId
并尝试获取
artistId
。参数区分大小写。

您将变量定义为
artistID
,并尝试获取
artistID
。参数区分大小写。

您的代码中有输入错误


它应该是
artistID
,而不是
artistID

您的代码中有一个打字错误


它应该是
artistID
,而不是
artistID

artistID!==artistID
哦,天哪。。。现在我觉得自己像个白痴。你只想回答这个问题,我会接受它,这样我们就可以关闭它,忘记它曾经发生过吗?
artistId!==artistID
哦,天哪。。。现在我觉得自己像个白痴。你只想回答这个问题,我会接受它,这样我们就可以结束这一切,忘记它曾经发生过吗?