0

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.

1 Answer 1

1

Yes, there is angular.fromJson utility function. See http://docs.angularjs.org/api/angular.fromJson

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.