status 404 with angular.js, but reachable via browser

I am running a simple web.py LAN server on port 8089 which returns "hello" for any request:

class predict:
    def GET(self):
        web.header('Content-Type','text/plain')
        return 'hello'

It is working fine when I access it via a browser. However, when I try to use angular.js, it keeps giving 404s. Firebug doesn't report any problems. Here is the HTML and angular code (which are in a local .html file):

<div ng-app>
<div ng-controller="TestCtrl">
<p>
<input placeholder="Type a word" type="text" ng-model="title"/><br/><br/>
Result = {{result}}
</p>
</div>
</div>

<script type="text/javascript">
function TestCtrl($scope, $http) {
    $scope.$watch('title', function (new_value) {
            $http({method: 'GET', url: 'http://10.33.133.166:8089/predict'}).
                    success(function(data, status, headers, config) {
                            $scope.result = data;
                    }).
                    error(function(data, status, headers, config) {
                            $scope.result = status;
                    });
    });
}
</script>

Any ideas why the behavior might be different in angular and browser?

Answers


It appears that cross-domain querying was the cause. I put the html file on the same server and everything is working fine now!


Need Your Help

how to detect keyevent in firefox

javascript firefox

I've write a web shell with javascript, but it doesn't work in firefox. But in IE and Chrome, it's fine. I've found that in firefox my script can't get the keyevent. So how can I fix this bug? Than...

How to use google places API

android google-places-api

I'm new to android programming and I want to ask how to get started with google places API. I've already searched so much on https://developers.google.com/places/training/basic-place-search and I'm...