-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi1.js
More file actions
22 lines (14 loc) · 671 Bytes
/
api1.js
File metadata and controls
22 lines (14 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let request = new XMLHttpRequest();
function displayNicely(apiData){
let newData = JSON.parse(apiData);
document.getElementById("name").innerHTML = "<strong>Name: </strong>" + newData.name + "<br>";
document.getElementById("eye_color").innerHTML += "<strong>Eye color: </strong>" + newData.eye_color + "<br>";
document.getElementById("birth_year").innerHTML += "<strong>Birth year: </strong>" + newData.birth_year;
}
request.onreadystatechange= function (){
if (this.readyState == 4 && this.status == 200){
displayNicely(this.responseText);
}
}
request.open("GET","https://swapi.co/api/people/4/")
request.send();