【问题标题】:Access GET parameter访问 GET 参数
【发布时间】:2015-03-11 04:45:51
【问题描述】:

我想发送我的server.js(在 AngularJS 控制器中)设置 id 参数,如下所示:

 $http
    .get('/getCst', {
        params: {               
            id: customerID
        }
     })
     .success(function (data,status) {
          $scope.customer = data
     });

但我不确定这是否是正确的方法以及在 Node.js server.js 中写什么:

app.get('/getCst', function (req, res) {

        console.log(//how do i get the id sent by the client?);     
});

【问题讨论】:

标签: angularjs node.js


【解决方案1】:

这是我的解决方案

app.get('/getCst/:id', function (req, res, next) {

        var id = req.params.id;    
});

【讨论】:

    【解决方案2】:

    试试这个:

    app.get('/getCst:id', function (req, res) {
    
            console.log(req.param('id'));     
    });
    

    【讨论】:

      【解决方案3】:

      app.get('/getCst', function (req, res) {

          var id = req.query.id;   
      

      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-10
        • 1970-01-01
        • 2017-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多