2

Why does the code below runs the error callback with no status? Web Developer in Firefox reports status code 200.

Is there any way to debug this?

<meta charset="utf8">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>

<script type="text/javascript">

    function RoomListCtrl($scope, $http) {

        $scope.getRooms = function() {

                $http({method: 'GET', url: 'http://code.angularjs.org'}).

                success(function(data, status, headers, config) {
                // this callback will be called asynchronously
                // when the response is available
                    alert('succes');
                }).

                error(function(data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                    alert('error');
                });
        }

        $scope.submit = function() {

            this.getRooms();
        }

    }

</script>

<body ng-controller="RoomListCtrl"><form ng-submit="submit()">
    <input type="text" value="" ng-model="search" name="search" >
</form></body>

3
  • Is that the actual code you're running? Sounds like you're running into cross-domain issues, where the actual request is being blocked (so no status either). Commented Oct 13, 2013 at 17:20
  • Yes, this is actual code. I am running this code as local file in Firefox. Could that cause the issue? Commented Oct 13, 2013 at 17:24
  • Even if you would run it through an HTTP server, it would generate an error because you can't generally perform cross-domain AJAX requests (unless the remote server handling the request has CORS enabled, but it doesn't look like code.angularjs.org has). Commented Oct 13, 2013 at 17:28

1 Answer 1

1

As @robertklep points out above, you can't make ajax request to another domain unless that domain explicitly allows it. See the CORS link he provided. One workaround to this (assuming you can't control the CORS policy for the server you're requesting data from) is to use a JSONP request if the server supports that.

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.