-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax5.html
38 lines (36 loc) · 1.07 KB
/
ajax5.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 lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="button">Load users</button>
<br><br>
<h1>users </h1>
<div id="users"></div>
<script>
document.getElementById('button').addEventListener('click', loadUsers);
function loadUsers() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'users.php', true);
xhr.onload = function() {
if(this.status) {
var users = JSON.parse(this.responseText);
var output = '';
for (var i in users) {
output += '<ul>' +
'<li>ID: ' +users[i].id+'</li>'+
'<li>Name' +users[i].name+'</li>'+
'</ul>';
}
document.getElementById('users').innerHTML = output;
}
}
xhr.send();
}
</script>
</body>
</html>