Here's the code for the entire $http implementation:
$http({
url: jsurl('profile.login'),
method: 'POST',
data: $.param({
username: $scope.username,
password: $scope.password,
csrfmiddlewaretoken: $.cookie('csrftoken')
}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function (data) {
$scope.success = true;
}).
error(function (data) {
$scope.success = false;
$scope.errors = data.errors;
});
The issue is that data in $http.error is a string despite returning the following response:
Content-Type:application/json; charset=UTF-8
Body: {"errors":{"username":{"messages":[["Pleaseenteryourusername."]]},"password":{"messages":[["Pleaseenterpassword."]]}},"success":false}
In jQuery I would normally use $.parseJSON() however I keep hearing about how I shouldn't use jQuery code within Angular code (I've yet to understand why this is) so I'm wondering if there's a more Angular canonical method to parsing error response to JSON.
Yes, there is angular.fromJson utility function. See http://docs.angularjs.org/api/angular.fromJson