-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
35 lines (35 loc) · 1.2 KB
/
index.html
File metadata and controls
35 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html>
<head>
<title> Person Information </title>
<meta charset="UTF-8">
<script>
var baseurl = "http://localhost:8080/persons";
function loadPersons(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",baseurl + "/all",true);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState ===4 && xmlhttp.status ===200){
var persons = JSON.parse(xmlhttp.responseText);
var tbltop = `<table>
<tr><th>Id</th><th>First Name</th><th>Last Name</th><th>Age</th></tr>`;
//main table content we fill from data from the rest call
var main ="";
for (i = 0; i < persons.length; i++){
main += "<tr><td>"+persons[i].id+"</td><td>"+persons[i].firstName+"</td><td>"+persons[i].lastName+"</td><td>"+persons[i].age+"</td></tr>";
}
var tblbottom = "</table>";
var tbl = tbltop + main + tblbottom;
document.getElementById("personinfo").innerHTML = tbl;
}
};
xmlhttp.send();
}
window.onload = function(){
loadPersons();
}
</script>
</head>
<body>
<div id="personinfo"> </div>
</body>
</html>