I'm new to both Rest API and Angularjs. I'm trying to display an alert message on the UI to show if the edit of my table has been succeeded or not. I wonder how could we send the alert from Rest api controller to angularjs? Any example please? Thanks
for example i'm trying to post something using angularjs http
$scope.savePlan = function (plan,code) {
$http({
method : 'POST',
contentType: 'application/json',
url : restUrl + "plans/update/"+ plan,
data: code
}).success(function(data) {
console.log('POST: ' + data);
}).error(function(data) {
console.log('POST ERROR: ' +data);
});
};
Rest api controller
@RequestMapping(value = "/update/{plan}", consumes = MediaType
.APPLICATION_JSON,
method = RequestMethod.POST)
public String savePlan(@PathVariable("plan") String plan,
@RequestBody String code) throws Exception {
String message="";
if (code== null || code.trim().length() == 0 ||
plan== null || plan.trim().length() == 0)
{
//instead of logger.error i want to send that error message to display on the UI
message = "Plan details and type must be provided." +null;
}
return message ; }
void
– Hung Cao Jan 24 at 0:55