Hi All,
This is the java side using jax-rs:
@POST
@Produces("application/json")
@Path("/save-all-words")
public Map<String, String> saveAllWords(MultivaluedMap<String, String>
temp) {
Map<String, String> result = new HashMap<>();
result.put("key", "value");
return result;
}
If I post with jQuery like this:
$.post("${pageContext.request.contextPath}/resource/save-all-words", {
a: ["a1", "a2"],
b: ["b1", "b2", "b3"]
}, function(data) {
alert(JSON.stringify(data));
})
then the variable temp on the java side will be populated (it'll will be a
map with 2 keys: "a" and "b", the value for the key "a" will be a list of
"a1", "a2").
How I do something like that in AngularJS? I tried this but it didn't work:
app.factory("testPOST", ["$resource", function($resource) {
return
$resource("${pageContext.request.contextPath}/resource/save-all-words",
null, {
headers: {"Content-Type": "application/x-www-form-urlencoded"}
});
}]);
app.controller("Controller", ["$scope", "$resource", "testJaxRS",
"testPOST",
function($scope, $resource, testJaxRS, testPOST) {
$scope.testPOST = function() {
var temp = testPOST.save({}, {a: ["a1", "a2"], b: ["b1", "b2",
"b3"]}, function() {
alert(JSON.stringify(temp));
});
};
}
]);
The reason I used headers: {"Content-Type":
"application/x-www-form-urlencoded"} is from
http://stackoverflow.com/questions/11442632/how-can-i-make-angular-js-post-data-as-form-data-instead-of-a-request-payload.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.