node.js - 在没有 bodyParser 的情况下从 AngularJS 请求 Node.js 中的数据

标签 node.js request angularjs express

在我的应用程序中,我需要使用主体解析器来请求参数(Node.js AngularJS 基于 angular-express-blog )。例如(AngularJS Controller ):

$scope.changeComment = (comment) ->
  $http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, $scope.comment).success (data) ->
    $scope.post = data.post

根据 AngularJS 文档 $http.post('/someUrl', data).success(successCallback);

但是我不知道如何在node.js express中找到这些数据。我只能使用 bodyParser,它只解析表单中的数据。

app.put '/api/post/:id/editComment/:cid' = (req, res) ->
  id = req.params.id;
  cid = req.params.cid;
  console.log req
  Post.findById id, (err, post) ->
    unless err
      comment = post.comments.id(cid)
      console.log req.body
      comment.text = req.body.text
      post.save (err1) ->

那么如何传输和抓取数据呢?

应用程序配置:

app.configure "development", ->
  app.use express.bodyParser()
  app.use express.methodOverride()
  app.use express.static(__dirname + '/public')
  app.use express.errorHandler(
    dumpExceptions: true
    showStack: true
  )

并查看文件https://gist.github.com/3189377

最佳答案

语法错误$scope.comment应该只是comment:

$scope.changeComment = (comment) ->
  $http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
    $scope.post = data.post

关于node.js - 在没有 bodyParser 的情况下从 AngularJS 请求 Node.js 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11675628/

相关文章:

javascript - Egghead.io webpack Angular 教程

angularjs - 使用 AngularJS 在客户端执行 HTTP 请求

java - Java 中的 HTTP PATCH 请求

arrays - Laravel 5 : Request validate multidimensional array

javascript - 在请求的 header 中发送正文选项

javascript - 未捕获的 TypeError : angular. 小写字母不是函数

angularjs - 我需要什么来包含那个 Angular Bootstrap 才可以工作

angularjs - 强制你的 mac 或 pc 进入休眠状态

node.js - 订阅不适用于 Apollo Server Express

node.js - Kubernetes 入口 : NodeJS application shows blank page