Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  10] [ 2]  / answers: 1 / hits: 5901  / 10 Years ago, mon, march 24, 2014, 12:00:00

I would like to use a web-service that takes in JSON object (The object binds two arrays) in a POST request and returns a JSON object array.



I would now like to send request to the webservice from my AngularJS. Here is my code:



wellApp.factory('Search', ['$resource',function($resource){

return $resource('/filetables/searchdata/:tagSearchInput',
{
},
{
searchData:{
method:'POST',
isArray: true,
params:{ tag: '@tagSearchInput.tag',
details: '@tagSearchInput.details'
}
}
})

}])


function myWellsCtrl($scope,$resource, Wells, Tags, Search) {

$scope.wellSearchResult = Search.searchData({tag: [TypeOfWell],
details: [Vertical]});
};


If I do this, I get a NullPointerException at the server side, meaning that the arguments that I pass are getting passed as null.



How do I pass in this object such that the server interprets them as an object containing two arrays. I'm new to AngularJS and am not able to understand the @ notation of assigning the incoming parameter. It'd be great if someone here can lend me some help.


More From » json

 Answers
4

You shouldn't need to include params in searchData since the JSON will be sent in the body of the POST request. Try removing them from searchData. Then in your controller, try calling your service like this:



Search.searchData({}, {tag: [TypeOfWell], details: [Vertical]})


Note the {} as the first parameter, which is the params for your request. The second {} is for the payload. This will send your JSON in the request payload instead of as params. Let me know if that doesn't work for you. I have done something similar to what you're doing and this way worked for me.


[#46589] Sunday, March 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
morganm

Total Points: 626
Total Questions: 95
Total Answers: 95

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;