javascript我没有用html显示ajax表为什么?
我正在尝试使用AngularJS和Ajax运行一个应用程序。我还使用一个返回JSON的Java控制器。不幸的是,html没有显示表格,我无法理解是什么问题,请帮助。我刚刚开始学习Ajax和angularJS。我正在尝试以Html格式输出一个表,以下是我的文件:
框架。js
var app = angular.module('frames', []);
app.controller("FramesController", function ($scope, $http) {
$scope.successGetFramesCallback = function (response) {
$scope.frameList = response.data;
$scope.errormessage="";
};
$scope.errorGetFramesCallback = function (error) {
console.log(error);
$scope.errormessage="Unable to get list of frames";
};
$scope.getFrames = function () {
$http.get('/mcga/frames').then($scope.successGetFramesCallback, $scope.errorGetFramesCallback);
};
});
框架。html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<title>Schools in our university</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="js/frames.js"></script>
</head>
<body ng-app="frames" ng-controller="FramesController">
<h1>Компьютерные корпуса</h1>
<div ng-controller="getFrames" ng-show="frameList.length > 0">
<table id="frameTable">
<thead>
<tr>
<th><h2>Id</h2></th>
<th><h2>Company</h2></th>
<th><h2>Model</h2></th>
<th><h2>Price</h2></th>
<th><h2>Amount</h2></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="frame in frameList" id="{{frame.id}}">
<td>{{frame.id}}</td>
<td>{{frame.company}}</td>
<td>{{frame.model}}</td>
<td>{{frame.price}}</td>
<td>{{frame.amount}}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
我的控制器是用java编写的,它从数据库中获取列表,并以JSON格式返回,工作正常。JSON已返回给我。以下是代码:
@RestController
public class MyController {
@Autowired
private Service service;
@GetMapping("mcga/frames")
public ResponseEntity<Object> showAllFrames()
{
List<frame> frameList=service.getAllFrames();
return ResponseEntity.ok(frameList);
}
}
还有我的控制器:
@Configuration
public class ControllerConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/frames").setViewName("frames");
}
}
# 1 楼答案
你把ng控制器放错了。一定是FramesController:类似这样的东西