Reputation: 589
I am having some issues trying to receive a response message from a Spring RESTful web service to an AngularJS client.
I am using ResponseEntity<String>
to return a response to the client. This works when only returning a status code but AngularJS fails with Unexpected token R
when I send a response message in the body.
What am I doing wrong?
return new ResponseEntity<String>(HttpStatus.OK);
But this does not work:
return new ResponseEntity<String>("Report was updated successfully", HttpStatus.OK);
AngularJs code:
$http.get(url, header)
.success(function(data, status, headers, config) {
// some logic
}).error(function(resp, status) {
// some logic
});
Response:
Upvotes: 4
Views: 4014
Reputation: 46
Is Angular expecting JSON or HTML/text back?
I've experienced issues in the past returning text/javascript or application/json instead of text/html. It looks like Angular is expecting JSON or JSONP in that instance, hence the Unexpected Token R (which is the first letter of your response string).
I could give a more precise answer, but I'd need to also know if you're using JSONP vs JSON, etc.
Upvotes: 1