如何使用http传递两种类型的值来支撑动作

时间:2018-12-21 04:31:27

标签: java jquery angularjs struts

我正在使用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?

1 个答案:

答案 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动作在模型中存在primaryUserDetailsapplicationFlow(我的意思是变量名的大小写应该匹配)