【发布时间】:2017-01-22 00:28:38
【问题描述】:
我创建了一个 Web 服务,当我使用这个 url (http://localhost:8080/jerseyweb/crunchify/ftocservice) 时,它会返回一个 JSON 格式的数据。现在我想通过Angular js 获取这些数据,但我无法获取。我尝试使用的代码如下:
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in names">
{{ x.id + ', ' + x.name }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
alert("hi");
$http.get("http://localhost:8080/jerseyweb/crunchify/ftocservice")
.success(function (data, status, headers, config) {
alert("hiee"); // i can not reach at this alert
$scope.names = data;
});
});
</script>
</body>
</html>
http://localhost:8080/jerseyweb/crunchify/ftocservice中的JSON数据如下
[{"id":98.24,"name":36.8}]
【问题讨论】:
-
控制台有错误吗??另外我认为成功函数只得到一个参数(数据)。尝试删除所有其他参数
-
我尝试过,但我无法输出任何东西........
-
也没有得到任何错误,但我尝试调试并发现调试调用无法进入:$http.get("localhost:8080/jerseyweb/crunchify/ftocservice") .success(function (data, status, headers, config) { alert("hiee"); // 我无法到达这个警报 $scope.names = data; });
-
尝试添加一个 .error(function(data){...}) 看看它是否进入。
-
是的,我只是尝试一下,然后它就进入了............
标签: json angularjs web-services