-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.html
41 lines (37 loc) · 1.19 KB
/
sample.html
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
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: #212121; color:white">
<!-- 0 UNSENT Client has been created. open() not called yet.
1 OPENED open() has been called.
2 HEADERS_RECEIVED send() has been called, and headers and status are available.
3 LOADING Downloading; responseText holds partial data.
4 DONE The operation is complete. -->
</body>
<script>
const requestUrl = 'https://api.github.com/users/hiteshchoudhary'
const xhr = new XMLHttpRequest();
xhr.open('GET', requestUrl)
xhr.onreadystatechange=function(){
const s=xhr.readyState;
if(s==4){
const data=JSON.parse(this.responseText);
console.log(data);
const avatar= data.avatar_url;
const name=data.login;
const n=document.getElementById('name');
n.innerHTML=name;
const i=document.getElementById('img');
i.src=avatar;
n.remove()
}
}
xhr.send();
</script>
<img src='' alt="hitesh sir" id="img"/>
<h1 id="name"></h1>
</html>