在http请求中传递多个参数(独立参数)

时间:2017-06-17 05:34:48

标签: angularjs

这是我的方法我只是在http请求中传递3个参数。我知道我们可以像单个对象一样传递,就像这样..

$scope.sendReq = function (responseStatus) {
    $scope.leaveStatus = responseStatus;
    $scope.leaveNote = $scope.cancelReason;
    $scope.Leave_type_id = $scope.LeaveTypeId;

    $scope.ajaxObj = { 
        leaveStatus: $scope.leaveStatus, 
        leaveNote: $scope.leaveNote, 
        Leave_type_id: $scope.Leave_type_id 
    };

    console.log($scope.ajaxObj)

    var requestHeaders = {
        "content-type" : 'application/json'
    }

    var httpRequest = {
        method: 'post',
        url: "/admin/cancelLeaveRequest",
        headers: requestHeaders,
        data: $scope.ajaxObj
    }

    $http(httpRequest).then(function(response){
        alert("success")
    })
}

现在我的疑问是,我们可以在帖子中传递多个参数吗?我们可以像这样传递它而不是将其作为单个对象发送吗?

var httpRequest = {
    method: 'post',
    url: "/admin/cancelLeaveRequest",
    headers: requestHeaders,
    data:  $scope.leaveStatus, $scope.leaveNote , $scope.Leave_type_id 
}

0 个答案:

没有答案