如何在页面上显示包含数据库内容的表?rest ajax春季启动应用程序



index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cars Selling</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="listCarsSelling.js"></script>
</head>
<body>
<h2>Cars Selling List</h2>
<table id="table-content">
<thead>
<tr>
<td>code</td>
<td>manufacturer</td>
<td>model</td>
<td>color</td>
<td>transmission</td>
<td>body_type</td>
<td>price</td>
</tr>
</thead>
</table>
</body>
</html>

listCarsSellling.js

$(document).ready(function(){
$.ajax(
{
type: "GET",
url: "http://localhost:8080/ListCarsSelling",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function(data){

for (var i=0; i<data.length; i++) {
var row = $('<tr><td>' + data[i].code + '</td><td>' + data[i].manufacturer
+ '</td><td>' + data[i].model + '</td><td>' + data[i].color + '</td><td>'
+ data[i].transmission + '</td><td>' + data[i].body_type + '</td><td>' 
+ data[i].price + '</td></tr>');

$('#table-content').append(row);
}
},

error: function(msg){
allert(msg.responseText);
}
});
})

错误为"404"的照片,供链接上参考http://localhost:8080/':在此处输入图像描述


我希望数据库中的数据在转到主页时立即显示。我该怎么做?我还想指出,我连接到数据库没有问题,因为在开发rest时,我能够提取json数据。我现在需要以某种方式展示它们。。

呃,这个问题非常普遍。项目结构不正确。应用程序文件在另一个包中,它应该是最重要的,如这里所示。omg

最新更新