1
function PhoneInfo($scope, $http) {
    $http({
        method: 'GET',
        url: 'myurl/?',
        params: { 'company': '1571', 'secret': 'complex15', 'mode': 'phoneinfo', 'outputtype': 'json' }
    }).success(function (data) {
        alert(data);
        $scope.PhoneState = data;
    }).error(function (data, status) {
        $scope.status = status;
        alert('Error');
    });
}

When calling the url directly from browser, its giving Json string but in above code, its giving error. I am very new to Angular JS. Please help, thanks

4
  • Can you post the error you are getting? Commented Jul 13, 2016 at 6:44
  • Possible duplicate of Angular JSON vs JSONP $promise Commented Jul 13, 2016 at 6:46
  • Angular converts the json automatically to an object when received. It issues an error if the received json is syntactically wrong. Commented Jul 13, 2016 at 7:08
  • Please provide the error you are getting to help, A Plunker would be great. Commented Jul 13, 2016 at 7:35

1 Answer 1

1

Please check the angularjs http documentation.

Use .then() and pass success and error functions.

function PhoneInfo($scope, $http) {
        $http({
            method: 'GET',
            url: 'myurl/?',
            params: { 'company': '1571', 'secret': 'complex15', 'mode': 'phoneinfo', 'outputtype': 'json' }
        }).then(function (response) {
            alert(response.data);
            $scope.PhoneState = response.data;
        },
        function (response) {
            $scope.status = response.status;
            alert('Error');
        });
    }
Sign up to request clarification or add additional context in comments.

3 Comments

A little correction: "The promise doesn't have success and error methods". The promises success and error still exists but they're deprecated. Of course, they shouldn't be used, but I doubt that is the cause of the issue.
I'm not sure but i just updated my answer.. It would be great if you (@CharlieH & @developer033) provide a link to the document contains success and error methods for http promise.
Please look inside angular code. success is implemented very well.

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.