-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex
More file actions
51 lines (46 loc) · 929 Bytes
/
Copy pathindex
File metadata and controls
51 lines (46 loc) · 929 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<script src ="./jquery-3.6.0.js"></script>
<script>
const prototype = `
<table>
<thead>
<tr>
__headers__
</tr>
<thead>
<tbody>
<tr>
__body__
</tr>
</tbody>
</table>
`
$.get('/person.json')
.then(function(response){
console.log(response);
});
$.get('/person.json')
.then(function(response){
let headersTemplate = '';
let bodyTemplate = '';
let headers = Object.keys(response[0]);
headers.forEach(function(header) {
headersTemplate += `<th>${header}</th>`
});
let template = prototype.replace(`__headers__`,headersTemplate)
$('body').prepend(template);
$.each(response,function(index,person){
bodyTemplate+=
`
<tr>
<td>${person.name}</td>
<td>${person.age}</td>
<td>${person.cars.join(', ')}</td>
</tr>
`
})
template = template.replace('__body__',bodyTemplate);
$('body').prepend(template);
})
</script>
</html>