Node.js req.params.locationid not grabbing ID
Node.js req.params.locationid not grabbing ID
我有下面的url,其中有一个特殊的ID:
http://localhost:3000/location/5733e37adcba0f6d5aa88cf5/review/new
这是一个带有表单的页面,表单将被填写并提交给api,并保存在我的数据库中。我遇到的奇怪问题是,在我的控制器中,
req.params.locationid
由于某种原因正在返回CCD_ 1。
这是我的控制器代码:
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);
}
});
};
知道为什么req.params.locationid
在我的其他控制器中工作得很好,但在这个控制器中不是出于某种原因吗?我的路由器可能是错的吗?
顺便说一句,形式如下:
action="", method="post", role="form"
和路由器:
/* 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);
相关文章:
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- :not选择器不适用于ul类-备选方案
- Javascript JSON.parse not working
- NodeJS Multer is not working
- React, Webpack: bundle.js is not generated
- Node.js req.params.locationid not grabbing ID