状态404与angular.js,但可通过浏览器访问

时间:2014-01-31 08:52:03

标签: angularjs web.py

我在端口8089上运行一个简单的web.py LAN服务器,它为任何请求返回“hello”:

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

我通过浏览器访问它时工作正常。但是,当我尝试使用angular.js时,它会继续提供404s。 Firebug没有报告任何问题。这是HTML和角度代码(在本地.html文件中):

<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>

为什么角度和浏览器的行为可能会有所不同?

1 个答案:

答案 0 :(得分:0)

似乎跨域查询是原因。我把html文件放在同一台服务器上,现在一切正常!