当我使用这个URL(http://localhost:8080/jerseyweb/crunchify/ftocservice)时,我制作了一个Web服务,它返回一个JSON格式的数据。现在我想通过Angular js
获取这些数据,但我无法得到它。该代码与我尝试,情况如下:Angularjs和Web服务
<!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}]
你有没有在控制台中的任何错误?另外我认为成功函数只有一个参数(数据)。尝试删除所有其他参数 – Kram
我尝试,但我不能得到任何东西出来........ –
也不会得到任何错误,但我尝试调试,发现调试调用不能进入此:$ http.get(“http:// localhost:8080/jerseyweb/crunchify/ftocservice”) .success(function(data,status,headers,config)alert(“hiee”); //我不能达到此警报 $ scope.names = data; }); –