get('url') 使用 AngularJS 和 ServiceStack webservice 的操作

get('url') operation using AngularJS and ServiceStack webservice

我是 AngularJS 的新手,我正在尝试从我使用 ServiceStack 快速创建的网络服务中获取 JSON 中的一些项目。当我在浏览器中尝试 URL 时,我可以看到 JSON 对象,但由于某种原因 AngularJS 无法成功获取数据。这是我的实现:

angular.module('SomeApp', []).controller('ItemsFetcher', [ '$http', function($http){

      var x = this;

      x.products= [
          {
            Name: 'Missing items',
            Description: 'Could not access server'
          }];

    $http.get('http://localhost:29029/json/reply/GetAllItemsRequest')
    .then(function(data){

      x.products = [
          {
            Name: 'Success',
            Description: 'Great stuff!'
          }];
      });
  }]);

视图如下:

<html ng-app="SomeApp">
<head>
    <title>My First App</title>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="ItemsFetcher as fetcher">
    <h3>PRODUCTS</h3>
    <div ng-repeat="item in fetcher.products">
        <div>{{item.Name}} - {{item.Description}}</div>
    </div>
</body>

正如我所说,如果我在浏览器中调用 http://localhost:29029/json/reply/GetAllItemsRequest,我可以得到 JSON 对象。

我错过了什么吗?知道为什么这不起作用吗?

如果有人可以从中受益,我必须启用 CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) 或在同一个地方托管网络服务和网站。