Javascript Node.js req.params.locationid未抓取ID
我有以下带有特殊ID的url:Javascript Node.js req.params.locationid未抓取ID,javascript,node.js,express,Javascript,Node.js,Express,我有以下带有特殊ID的url: http://localhost:3000/location/5733e37adcba0f6d5aa88cf5/review/new 这是一个包含表单的页面,该表单将被填写并提交到api,并保存在我的数据库中。我遇到的奇怪问题是,在我的控制器中 req.params.locationid 由于某种原因返回未定义的 这是我的控制器代码: module.exports.doAddReview = function(req, res) { var req
http://localhost:3000/location/5733e37adcba0f6d5aa88cf5/review/new
这是一个包含表单的页面,该表单将被填写并提交到api,并保存在我的数据库中。我遇到的奇怪问题是,在我的控制器中
req.params.locationid
由于某种原因返回未定义的
这是我的控制器代码:
module.exports.doAddReview = function(req, res) {
var requestOptions, path, locationid, postdata;
locationid = req.params.locationid;
console.log("\n>>>> " + req.params.locationid + " <<<<\n");
path = "/api/locations/" + locationid + '/reviews';
postdata = {
author: req.body.name,
rating: parseInt(req.body.rating, 10),
reviewText: req.body.review
};
requestOptions = {
url : apiOptions.server + path,
method : "POST",
json : postdata
};
request(requestOptions, function(err, response, body) {
if (response.statusCode === 201) {
res.redirect('/location/' + locationid);
} else {
_showError(req, res, response.statusCode);
}
});
};
和路由器:
/* Locations pages */
router.get('/', ctrlLocations.homelist);
router.get('/location/:locationid', ctrlLocations.locationInfo);
router.get('/location/:locationid/review/new', ctrlLocations.addReview);
router.post('/location/:locaitonid/review/new', ctrlLocations.doAddReview);
因为您在路由器文件中有键入错误
router.post('/location/:locationid/review/new', ctrlLocations.doAddReview);
哈,我看了那么多次,我想有时候你只需要再看一眼。谢谢欢迎:)如果有帮助,那就接受它作为回答。我会的,但我必须等10分钟哈哈,我不知道。很抱歉,为了名誉而不顾一切。
router.post('/location/:locationid/review/new', ctrlLocations.doAddReview);