AngularJS Post Request Undefined



我正在发出一个帖子请求,将注释插入我的MongoDB数据库。尝试进行此插入时,我收到错误 500。我相信这是由于提出请求时未收到价值。发布这些值时我哪里出错了?

app.post('/addComment', (req, res) =>{
console.log(req.body.description, typeof(req.body.description));
var com = new Comment({
description: req.body.description,
sentiment: ml.classify(req.body.description),
status: req.body.status,
});
com.save(function(err, insComment){
if(err){
console.log('Error loading data');
}
else{
res.send(insComment);
}
});
});

控制器.js

exports.CommentController = function($scope, $http){
$scope.addComment = function(){
$http({
method :'POST',
url: '/addComment',
headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'},
data:{
//username:$scope.username,
description: $scope.description,
//sentiment: $scope.sentiment,
status:$scope.status,
}
}).then(function (response){
$scope.user = response;
console.log('DESCRIPTION ' + typeof($scope.description))
//$scope.user = response;
}, function(err){
console.log(err);
})
}
}
$scope.addComment = function(){
$http.post('/addComment', {
description: $scope.review.description,
status: $scope.review.status,
},
{headers: {'Content-Type': 'application/json'}}).
success(function(data){
$scope.user = data;
console.log('DESCRIPTION 2 ' + typeof($scope.description))
console.log(data);
}).error(function(err){
console.log(err);
});
};

前端

<div class="row p-b-25">
<div class="col-12 p-b-5">
<input type="text" 
ng-model="review.description">
</div>
<add-comment></add-comment>
</div>

请添加完整的网址并尝试。

e:g

$http({
method :'POST',
url: 'http://localhost:3000/addComment',

相关内容

  • 没有找到相关文章

最新更新