-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.js
More file actions
36 lines (33 loc) · 1001 Bytes
/
callback.js
File metadata and controls
36 lines (33 loc) · 1001 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
function ajax(callback) {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://jsonplaceholder.typicode.com/users");
xhr.onload = function () {
if (xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.send();
}
function render(resultText) {
const result = JSON.parse(resultText);
let table = "";
result.forEach((data) => {
table += `<tr>
<td>${data.id}</td>
<td>${data.name}</td>
<td>${data.username}</td>
<td>${data.email}</td>
<td>
${data.address.street},
${data.address.suite},
${data.address.city}
${data.address.zipcode}
</td>
<td>${data.company.name}</td>
</tr>`;
});
// return table;
const tbody = document.getElementById("tablebody");
tbody.innerHTML = table;
}
ajax(render);