我想用一个Web服务,它在JSON对象(Object绑定两个阵列)的POST请求,并返回一个JSON对象数组。
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.
我现在想从我的AngularJS发送请求到web服务。这里是我的code:
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"]}); };如果我这样做,我在服务器端得到一个NullPointerException异常,这意味着我传递参数越来越为空过去了。
If I do this, I get a NullPointerException at the server side, meaning that the arguments that I pass are getting passed as null.
我如何传递这个对象使得服务器间$ P $其中pts它们含有两个数组的对象。我是新来AngularJS,我不能够理解分配传入的参数的@符号。这将会是巨大的,如果有人在这里可以借给我一些帮助。
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.
推荐答案您不应该需要在searchData PARAMS因为JSON将在POST请求的主体发送。尝试从searchData删除它们。然后在你的控制器,尝试调用你的服务是这样的:
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"]})注意{}作为第一个参数,这是你的要求的PARAMS。第二个{}是有效载荷。这将在请求负载而不是作为PARAMS发送您的JSON。让我知道,如果不为你工作。我做了类似于你在做什么东西,这种方式为我工作。
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.
更多推荐
如何在JSON对象传递到angularjs资源
发布评论