In my AngularJS application, I collect user input and store it in painting objects. These objects are then sent to my Spring Boot backend which saves them to a MongoDB server and returns an ID. However, when attempting to POST data to the server, I receive an empty response despite the object being successfully stored.
AngularJS Code:
<!DOCTYPE html>
<html lang="en-US">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.1/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Name : <input type="text" ng-model="name"></p>
<h1>Hello {{name}}</h1>
...
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope','$http', function($scope,$http) {
...
}]);
</script>
</body>
</html>
SpringBoot Java POST Method:
@RequestMapping(method = RequestMethod.POST, value = "/paintings")
public String save(@RequestBody Painting painting){
repository.save(painting);
System.out.println("Function called");
return painting.getID();
}
Postman Response:
I am perplexed by the fact that I keep receiving an empty response in the browser console even though the server is indeed sending a response back.