pareshm
pareshm

Reputation: 4984

How to Send Multiple params to JAVA API using AngularJS

I have Java API function as bellow :

     public Response abc(@FormParam("tenderIdsJsonArray") JSONArray tenderIdsJsonArray, @FormParam("tenderRejectTime") String tenderRejectTime,@FormParam("rejectResonType")  String rejectResonType) {

     }

I am sending data from AngularJs

     $http({
      method: 'POST',
      url: URL,
      data: {bacJsonArray:[1543],RejectTime:"12",rejectResonType:"test"}    
    }).success(function (response) {
      loaderServ.hide();
      resolve(response);
    }).error(function (error) {
      loaderServ.hide();
      reject(error);
    });

I am getting all parameters of function as null at API side

where i need to make change

I also tried sending:

JSON.stringify({bacJsonArray:[1543],RejectTime:"12",rejectResonType:"test"} 
    })

or params:{alldata}

I also tried changing at server side:

     public Response abc(JSONArray bacJsonArray,String RejectTime,String rejectResonType) {

     }

But in all cases i am recieving Null at server side

Upvotes: 1

Views: 78

Answers (2)

pareshm
pareshm

Reputation: 4984

Below way i used and it worked.

    $http({
        method: 'POST',
        url: url,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        transformRequest: function(obj) {
            var str = [];
            for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        },
        data: {username: $scope.userName, password: $scope.password}
    }).success(function () {});

Upvotes: 1

var req = {
    method: 'POST',
    url: 'http://example.com',
    data: { test: 'test' }
};

$http(req).then(function(){
    // success
}, function(){
    error
});

Upvotes: 0

Related Questions