當我將這個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