-
Notifications
You must be signed in to change notification settings - Fork 6
/
data.html
38 lines (32 loc) · 976 Bytes
/
data.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ajax Get Data</title>
</head>
<body>
<div>
<table id="data">
</table>
</div>
</body>
<script type="text/javascript">
var ajax = new XMLHttpRequest();
ajax.open("GET", "page.php", true);
ajax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var table = '<tr><th>No</th><th>NIM</th><th>Nama</th><th>Alamat</th></tr>';
ajax.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200)
{
var data = JSON.parse(this.responseText);
data.forEach(toTable);
document.getElementById("data").innerHTML = table;
}
};
ajax.send();
function toTable(item, index){
table += '<tr><td>'+item.id+'</td><td>'+item.nim+'</td><td>'+item.nama+'</td><td>'+item.alamat+'</td></tr>'
}
</script>
</html>