我正试图从一个API中获取有关动物及其速度的信息。
x1c 0d1x的数据
信息应该保存在一个有5列的表中。它应该看起来像这样:
的
你会在下面找到我写的代码。问题是只有两个按钮加载,但没有信息表。你知道错误可能是什么吗?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-1srTifKwwmIWHsyIaapyeJQY2XxzfjIHpftPvwHSi97Mfm4cZNKDBAdVSrtRvti5" crossorigin="anonymous">
<script> src = "https://code.jquery.com/jquery-3.7.1.min.js"
integrity = "sha384-1H217gwSVyLSIfaLxHbE7dRb3v4mYCKbpQvzx0cegeju1MVsGrX5xXxAvs/HgeFs"
crossorigin = "anonymous"
</script>
</head>
<body class="text-center">
<br />
<button class="btn btn-primary btn-lg" id="prev">Prev</button>
<button class="btn btn-primary btn-lg" id="next">Next</button>
<br />
<table id="table" class="table table-striped table-striped table-hover">
<tbody id="tableBody" />
</table>
<script src=" myScript.js">
</script>
</body>
</html>
字符串
//在myScript.js下面
$(document).ready(function () {
/*Variablen */
var counter = -5;
var end = false;
$("#next").click(function () {
if (!final) {
counter = counter + 5;
}
$.get("http://localhost:8080/webService/api/velocitiespagination?start=" + counter, function (velocities) {
createTable(velocities);
});
});
$("#prev").click(function () {
counter = counter - 5;
if (counter < 5){
counter = 0;
}
$.get("http://localhost:8080/webService/api/velocitiespagination?start=" + counter, function (velocities) {
createTable(velocities);
});
});
createTable(velocities);
});
function createTable(velocities) {
var text = "<tbody><tr><th>Tier<>/th><th>Maximalgeschwindigkeit Tier</th></tr>";
$.each(velocities, function (key, velocity) {
text = text + "<tr><td>" + velocity.animal + "</td><td>" + velocity.velocity + "</td></tr>";
});
text += "</tbody>"
$("#myTable").html(text);
end = velocities.length === 0;
}
型
1条答案
按热度按时间jgzswidk1#
我想如果你查看控制台,你会看到关于
$(...).ready()
不是函数的错误,因为你没有加载jQuery。在执行此操作时,您将声明变量
src
、integrity
和crossorigin
字符串
您希望将它们作为script标记上的属性,如下所示
型