【问题标题】:Sending variable by http get通过 http get 发送变量
【发布时间】:2017-11-30 16:58:55
【问题描述】:

我在通过 http.get 发送变量时遇到问题,有人可以纠正我吗?

$http.get("/product/products", { 'quantity': 5 }).then(function (resp) {
    $scope.products = resp.data;
})

非常感谢

【问题讨论】:

    标签: angularjs node.js angularjs-http


    【解决方案1】:

    您应该将其作为配置对象的params 属性发送。

    $http.get("/product/products", { params: { 'quantity': 5 }})
    

    【讨论】:

    • 如果我想在节点中使用它,我必须这样做:console.log(req.params);或 console.log(req.body); ??
    • 但是当我使用 req.body 或 req.params 时,console.log 返回我为空{}
    • @Turqus 因为你没有在路由中提到参数,你应该改用req.query
    【解决方案2】:

    无法为get 请求发送请求正文。您可以将其更改为 POST 请求或将变量发送为 params

    $http.get("/product/products", { params: { 'quantity': 5 }}).then(function (resp) {
        $scope.products = resp.data;
    })
    

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多