【发布时间】:2014-02-25 09:31:49
【问题描述】:
我尝试通过 $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 发生了变化,在后一种情况下,firebug 恰好在控制台中显示以下内容: Image
我不确定出了什么问题。我使用 json 数据在谷歌地图上绘制点。 test.json 完美运行。我假设可能是不允许外部数据源(与当前域不同的域),或者即使在从外部源返回数据之前,Angular 也会继续渲染谷歌地图。
【问题讨论】: