0
Hers is my code in html pasted in WebContent folder created using Dynamic Web Project in eclipse:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http){
$http.get('country_codes.json').success(function(data) {
$scope.countries = data;
});
});
</script>
</head>
<body ng-controller="CountryCtrl">
<h2>Angular.js JSON Fetching Example</h2>
<table>
<tr>
<th>Code</th>
<th>Country</th>
<th>Population</th>
</tr>
<tr ng-repeat="country in countries | orderBy: 'code' ">
<td>{{country.code}}</td>
<td>{{country.name}}</td>
<td>{{country.population}}</td>
</tr>
</table>
</body>
</html>
json數據寫在「country_codes.json」中,該文件放置在已放置html文件的相同位置。如何在eclipse中使用angularJs從服務器讀取json數據?
] 1
但我得到的輸出如下圖所示image.Please讓我知道它爲什麼不從服務器上讀取數據
感謝它的工作,但請讓我知道我應該在哪裏放置文件,我必須從eclipse動態web項目中讀取數據。另一件我經常困惑的事情是,我把json文件放在與html文件相同的位置,所以爲什麼說我有從服務器讀取文件。 – user3907559
Pleasse讓我知道我在上面問了什麼? – user3907559