Angular JS,构造一个动态路径请求

时间:2016-07-07 19:15:01

标签: angularjs json request

我想构建跟随请求

http://www.example-server.com/ {{PARAM-1}} / {{PARAM-2}} /示例

这是实际的请求

    //
    // Summary:
    //     Multiline mode. Changes the meaning of ^ and $ so they match at the beginning
    //     and end, respectively, of any line, and not just the beginning and end of the
    //     entire string. For more information, see the "Multiline Mode" section in the
    //     Regular Expression Options topic.
    Multiline = 2,

这是我想要构建的请求

$http({
            method:'POST',
            url:"http://www.example-server.com/server/request/example",
            data : {
              phone: $scope.phone,
              company: $scope.company,
              contract: '1',
              privacy: '1',
              email: $scope.email
            },
            headers: {
                'Content-Type': 'application/json'
            }
        })

1 个答案:

答案 0 :(得分:0)

试试这个

 var1 = "path1";
 var2 = "path2";

 $http({
        method:'POST',
        url:"http://www.example-server.com/" + var1 + "/" + var2 + "/example",
        data : {
          phone: $scope.phone,
          company: $scope.company,
          contract: '1',
          privacy: '1',
          email: $scope.email
        },
        headers: {
            'Content-Type': 'application/json'
        }
    })