当我将这个json保存在本地计算机中并在我的angularjs脚本中使用它时。它工作正常。但是,当我使用直接服务器,这不是为什么。如何从服务器获取php Web api json的数据到使用angularJs?
我的脚本中缺少什么?
我的JSON文件>
http://deals.ownaroof.com/api/webservices/locations_list.json
HTML>
<div ng-controller='prefferedCtrl'>{{locations}}</div>
SCRIPT>
(function(){
angular.module('myapp',['ngRoute'])
//afactory to consume webservices and return data to controllers.
.service('webServices',['$http',function($http){
return {
getLocations : function(){
return $http.get('http://deals.ownaroof.com/api/webservices/locations_list.json').then(function(response){ //wrap it inside another promise using then
return response.data.response.locations; //only return locations
});
}
}
}])
//define controller and inject webServices service as dependency.
.controller('prefferedCtrl',['webServices','$scope',function(webServices,$scope,$ngRoute){
webServices.getLocations().then(function(response){
$scope.locations = response; //Assign data received to $scope.data
});
}])
})();
如何使用这个json文件任何人请给我建议。
你是否在控制台中看到数据? – Sajeetharan
未显示 有错误 angular.min.js:102错误:[ng:areq] http://errors.angularjs.org/1.3.14/ng/areq?p0=axajCtrl&p1=not%20a %20function%2C%20got%20undefined – user1727852
即zip文件 http://webstrokes.in/json-error.zip plz sir帮助我。 – user1727852