使用 AngularJS 和 Express 的 PUT 请求
PUT Request with AngularJS and Express
当我执行放置请求和请求的 console.log(response)
时,我只得到一个像 {"res":1}
这样的 JSON 对象,而不是得到整个 json 对象它的变化是为了在数据库中更新他。
控制器:
$scope.doneEdit = function (components) {
console.log(components);
components.editing = false;
if (components.editing === false) {
$http.put('/propt/' + components._id).then(function (response) {
console.log(response.data);
});
}
}
快递
app.put('/propt/:id', function(req,res) {
console.log(req.body);
testDb.update({_id:req.params.id}, req.body, {}, function(err, numReplaced){
res.statusCode = 200;
res.send(req.body);
})
})
您应该将要发送的数据作为第二个参数传递给 put
方法:
$http.put('/propt/' + components._id, {someValue:components.someValue})
您可以在此处找到文档:https://docs.angularjs.org/api/ng/service/$http#put
当我执行放置请求和请求的 console.log(response)
时,我只得到一个像 {"res":1}
这样的 JSON 对象,而不是得到整个 json 对象它的变化是为了在数据库中更新他。
控制器:
$scope.doneEdit = function (components) {
console.log(components);
components.editing = false;
if (components.editing === false) {
$http.put('/propt/' + components._id).then(function (response) {
console.log(response.data);
});
}
}
快递
app.put('/propt/:id', function(req,res) {
console.log(req.body);
testDb.update({_id:req.params.id}, req.body, {}, function(err, numReplaced){
res.statusCode = 200;
res.send(req.body);
})
})
您应该将要发送的数据作为第二个参数传递给 put
方法:
$http.put('/propt/' + components._id, {someValue:components.someValue})
您可以在此处找到文档:https://docs.angularjs.org/api/ng/service/$http#put