-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (32 loc) · 1.21 KB
/
script.js
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
// const xhr = new XMLHttpRequest();
// xhr.onreadystatechange = function(){
// console.log(xhr.readyState);
// }
// xhr.open('GET','https://jsonplaceholder.typicode.com/todos/1');
// xhr.send();
const input = document.getElementById("userInput");
const form = document.querySelector("form");
const card = document.querySelector("#card");
form.addEventListener("submit", (e) => {
e.preventDefault();
const xhr = new XMLHttpRequest();
const requestUrl = `https://api.github.com/users/${input.value}`;
xhr.open("GET", requestUrl);
xhr.addEventListener("load", () => {
const data = JSON.parse(xhr.responseText);
console.log(data);
document.getElementsByClassName(
"photo"
)[0].innerHTML = `<img class="image" src= ${data["avatar_url"]} alt="" />`;
document.getElementsByClassName(
"followers"
)[0].innerHTML = `<span>Name : ${data["name"]} <br/>
Address : ${!data["location"] ? "Not Given" : data["location"]} <br/>
Followers : ${data["followers"]}</span><br/>
About : ${data["bio"]}</span>`;
});
xhr.send();
card.classList.remove("hidden")
input.value = "";
});
// console.log('here:',xhr.responseText);