In my Maven application, I have implemented a PUT HTTP request mapped to a specific function using the Spring Framework. The goal is to perform some internal checks and then send a text response. Subsequently, I need to trigger this request from AngularJS and store the received response in a variable within the AngularJS controller. Below is an example of what I have attempted:
@RequestMapping(path="/play", method={RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public String someFunction(){
//...
return "some text";
}
$scope.getResponse = function(param1, param2...){
$http.post("url..").then(
function(response){
$scope.response = response.data.response;
console.info('success');
},
function(response){
console.info('failure');
})
}
The HTTP mapping is functioning correctly when accessed from a browser; however, the challenge lies in storing the textual response into an AngularJS variable within the controller.