1var xhr = new XMLHttpRequest();
2
3xhr.onload = function () {
4
5 if (xhr.status >= 200 && xhr.status < 300) {
6
7 const users = JSON.parse(xhr.response);
8 const content = document.getElementById("user_content");
9
10 for(let i in users){
11 let user_name = document.createElement("p");
12 let text = document.createTextNode(`User ID ${users[i].id}: ${users[i].title}`);
13 user_name.appendChild(text);
14 content.appendChild(user_name);
15 }
16
17 } else {
18 console.log('The request failed!');
19 }
20
21 console.log('This always runs...');
22};
23
24xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts');
25xhr.send();