The back end guy wants to send me a string, which will be returned by $http.post
. If he sends me something like "success
", I will get error like "parsing Json failed". I want him to wrap the string into object like "{"message": "success"}
", which works fine. But other back end guys say that front end should comply with back end, so they will just send me the string. Is there any way that I can read the string?
This is the code I use if he sends me "{"message": "success"}
", which works perfectly:
AdminService.saveCache(cache)
.then(function(data) {
var data = data.data;
if (data.message == "success") {
scope.successMessage = "Cache hours saved successfully";
} else {
scope.errorMessage = data.message;
}
}, function() {
scope.errorMessage = "Submission failed";
});
$http
can properly resolve/reject the promise appropriately.