我是angular JS的新手。我有一个控制器(.js文件),我在其中编写了一个函数来对后端进行http get调用。如下所示:
$http({
url: "services/rest/1.0/project/employeeDetails",
method: 'GET',
headers: config,
transformResponse: function (data) {
var x2js = new X2JS();
var json = x2js.xml_str2json(data);
return json;
}
}).success(function (response) {
alert("success for account details with response:"+response);
if (response && response.siteDetailsList.errorCode == 0)
$scope.accountdetails = response;
});现在的问题是,我需要向我的url添加两个查询参数,我在上面的代码片段中提到了这两个参数,所以最终的URL将如下所示:
services/rest/1.0/project/employeeDetails ? param1=world & param2=hello我从我的param2文件的输入文本框中获得的这个HTML值和HTML值。知道如何将动态查询参数附加到此URL吗?
发布于 2017-02-16 16:41:35
您可以使用params配置属性:
$http({
url: "services/rest/1.0/project/employeeDetails",
method: 'GET',
headers: config,
params: {
param1: someValue,
param2: anotherValue
},
transformResponse: function (data) {
var x2js = new X2JS();
var json = x2js.xml_str2json(data);
return json;
}
}).success(function (response) {
alert("success for account details with response:"+response);
if (response && response.siteDetailsList.errorCode == 0)
$scope.accountdetails = response;
});发布于 2017-02-16 17:19:19
您可以使用AngularJS中的$httpParamSerializer服务。
https://docs.angularjs.org/api/ng/service/$httpParamSerializer
对象:
var obj = {
param1:"world",
param2:"hello"
}使用httpParamSerializer:
$httpParamSerializer(obj)返回:
param1=test¶m2=world发布于 2017-02-16 17:57:33
var obj =
{
param1:"world",
param2:"hello"
}
$http.post("services/rest/1.0/project/employeeDetails", obj)
.then(function (response)
{
return response`enter code here`;
},`function (error){ return error;});`
https://stackoverflow.com/questions/42268530
复制相似问题