-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitApi.js
More file actions
23 lines (18 loc) · 776 Bytes
/
gitApi.js
File metadata and controls
23 lines (18 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const btn = document.querySelector('.btn')
const userImg = document.querySelector('.userImg')
const userName = document.querySelector('.userName')
const userDate = document.querySelector('.userDate')
const fetchData = function() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.github.com/users/ringcoa", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
const json = JSON.parse(xhr.response)
userImg.innerHTML = `<img src="${json.avatar_url}" alt="">`
userName.innerHTML = `유저 이름 - ${json.login}`
userDate.innerHTML = `생성날짜 - ${json.created_at}`
}
};
xhr.send();
}
btn.addEventListener('click',fetchData)