我正在使用strut动作,并希望使用angularJS的$ http传递一个对象和一个文本,并传递给strut动作类。
var applicationFlow = $('#txtApplicationFlow').val();
//alert(applicationFlow);
var primaryUserDetails ={
firstName: $scope.txtFirstName,
middleName:$scope.txtMiddleName,
lastName: $scope.txtLastName,
familyCode:$scope.stFamilyCode,
add1: $scope.stSenderAdd1,
add2: $scope.stSenderAdd2,
add3: $scope.stSenderAdd3,
city: $scope.stSenderCity,
state: $scope.state,
zipCode: $scope.stZipCode,
country: $scope.country,
phoneNo: $scope.txtPhoneNo,
emailID: $scope.txtEmailId,
rName: $scope.txtRitvikName,
rActive: $scope.chkIsDecessed,
pwd: $scope.stPassword
};
//var contextPath = "addPrimaryUser.do"+"?primaryUserDetails="+ JSON.stringify(priaryUserDetails)+"&applicationFlow="+applicationFlow;
var contextPath = "addPrimaryUser.do"+"?primaryUserDetails="+ priaryUserDetails+"&applicationFlow="+applicationFlow;
$http({
method : "POST",
url : contextPath,
data: primaryUserDetails
}).then ..........
如何同时传递applicationFlow和primaryUserDetails?
答案 0 :(得分:0)
您必须在请求正文中传递它,这意味着data
调用的$http
属性,而不是查询参数中的URL
。
var contextPath = "addPrimaryUser.do"
$http({
method : "POST",
url : contextPath,
data: {
primaryUserDetails: primaryUserDetails,
applicationFlow: applicationFlow
}
}).then(...)
OR
var contextPath = "addPrimaryUser.do"
$http.post(contextPath, {
primaryUserDetails: primaryUserDetails,
applicationFlow: applicationFlow
}).then(...)
仅确保您的strut动作在模型中存在primaryUserDetails
和applicationFlow
(我的意思是变量名的大小写应该匹配)