2014-02-25 36 views
0

我试图通过$ http从Angular JS中的外部源获取数据,但它返回空白数据。用于从本地文件获取数据时的相同服务非常完美。

从本地源获取数据的代码:

controllers.controller('listController', ['$scope', '$http', 
    function($scope,$http) { 

    var data = null; 

    $http.get('js/test.json').success(function(data) { 
      $scope.markers = data.hooks; 

     }); 

      $scope.map = { 
      center: { 
       latitude: 45, 
       longitude: -73 
      }, 
      zoom: 2 
     }; 

    }]); 

从外部源获取数据的代码:

controllers.controller('listController', ['$scope', '$http', 
    function($scope,$http) { 

     var data = null; 

     $http.get('http://115.113.151.200:8081/user/maphook/mobile/generate_list.jsp').success(function(data) { 
       $scope.markers = data.hooks;   
      }); 

      $scope.map = { 
       center: { 
        latitude: 45, 
        longitude: -73 
       }, 
       zoom: 2 
      };    
    }]); 

正如你所看到的只是URL已更改,在后一种情况下,萤幕恰好在控制台中显示以下内容: Image

我不知道什么是错的。我使用json数据绘制谷歌地图上的点。 test.json完美工作。我假设它可能是外部数据源(不同于当前域),或者甚至在数据从外部源返回之前,Angular继续渲染谷歌地图。

回答

0

,如果你打算使用AJAX跨域发送和接收JSON数据您应该JSONP阅读。它支持angular.js,你只需要找到一个例子(谷歌已经加载)。

Jsonp是你需要的。