我是java ee和angular JS的初学者,我从网站找到了一个代码(http://www.simplecodestuffs.com/angularjs-interacting-with-java-servlet-using-json/) 我试图在eclipse中实现它。 但当我点击按钮"从服务器获取数据"输出没有按预期显示
输出:
gridPanel
这是我的JSP:
First Name: {{person.firstName}}
Last Name: {{person.lastName}}
这是我的servlet:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>AJAX with Servlets using AngularJS</title>
<script type="text/javascript" src="jas/angular.min.js"> </script>
<script>
var app = angular.module('myApp', []);
function MyController($scope, $http) {
$scope.getDataFromServer = function() {
$http({
method:'GET',
url:'http://localhost:8080/Angular/AngularJsServlet'
}).success(function(data, status, headers, config) {
$scope.person = data;
}).error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
};
</script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="MyController">
<button ng-click="getDataFromServer()"> Fetch data from server </button>
<p>First Name: {{person.firstName}}</p>
<p>Last Name: {{person.lastName}}</p>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
由于3f2232b5,
$controller
将不再在窗口上查找控制器。查看控制器窗口的旧行为最初打算用于示例,演示和玩具应用程序。我们发现允许全局控制器功能鼓励不良做法,因此我们决定默认禁用此行为。要迁移,请使用模块注册控制器,而不是将它们公开为全局
由于b54a39,
$http
已弃用的自定义回调方法 -.success()
和.error()
- 已被删除。您可以使用标准.then()
/.catch()
promise方法,但请注意方法签名和返回值不同。$http(...) .then(function onSuccess(response) { // Handle success var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... }).catch(function onError(response) { // Handle error var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; ... });