【问题标题】:Not able to get json request in express delete with restangular?无法使用restangular在快速删除中获取json请求?
【发布时间】:2026-01-25 02:25:02
【问题描述】:

这是我用来删除对象的restangular代码

$scope.delO = (id){
  Restangular
    .one("footer",id)
    .get()
    .then((ob)=>{
      ob.remove();
    }
    .catch....
}

当我在浏览器中验证时,请求正在正确发送。这是快递代码

route.delete("/",(req,res,next)=>{
  console.log(req.body);
  helper['del'](req.body._id)
    .then(()=>{
      res.status(200).end();
    })
    .catch((err)=>{
      res.status(400).json({err:err.message});
    });
});

req.body 为空。根据question here我看应该在参数里面。

谁能解释一下我哪里出错了?

编辑

为了消除一些混乱,这里是浏览器的屏幕截图

【问题讨论】:

    标签: javascript node.js express restangular


    【解决方案1】:

    DELETE 动词中不能有数据帖子。所以为了让上面的代码工作,我不得不修改它为

      $scope.delExisting = ()=>{
        console.log($scope.form._id);
        Restangular
          .one("footer/"+$scope.form._id)
          .remove()
          .then((data)=>{
            $scope.list();
          })
          .catch((err)=>{
            console.log("Error");
          });
      }
    

    并在快递上采用要从uri中删除的元素的id

    【讨论】: