1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Document</ title >
7
+ < style >
8
+ body {
9
+ height : 100vh ;
10
+ display : flex;
11
+ justify-content : center;
12
+ align-items : center;
13
+ font-size : 18px ;
14
+ font-weight : bold;
15
+ font-family : system-ui, sans-serif;
16
+ background-color : # 373A40
17
+ }
18
+
19
+ .container {
20
+ text-align : center;
21
+ background-color : # EEEEEE ;
22
+ width : 300px ;
23
+ height : 250px ;
24
+ border-radius : 10px ;
25
+ padding : 20px ;
26
+ }
27
+
28
+ # profile-pic {
29
+ margin-top : 48px ;
30
+ height : 100px ;
31
+ width : 100px ;
32
+ border-radius : 50% ;
33
+ border : 5px solid # DC5F00 ;
34
+ }
35
+ </ style >
36
+ </ head >
37
+ < body >
38
+ < div class ="container ">
39
+ < img id ="profile-pic " src ="" alt ="GitHub Profile Picture " >
40
+ < p id ="followers-count "> </ p >
41
+ </ div >
42
+
43
+ <!-- To Know about : XMLHttpRequest: readyState property, refer this link.
44
+ https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState -->
45
+
46
+ < script >
47
+ // Sending XML request also known as Ajax Request.
48
+
49
+ // Creating a object using new keyword
50
+ const xhr = new XMLHttpRequest ( )
51
+ const requestUrl = "https://api.github.com/users/AayushYadavz"
52
+
53
+ // Sending request
54
+ xhr . open ( "GET" , requestUrl ) // State 1
55
+
56
+ // Tracking continuous State change
57
+ xhr . onreadystatechange = function ( ) { // On every state change function excecutes continuously
58
+ // Checking State change using console.log
59
+ // console.log(xhr.readyState);
60
+ if ( xhr . readyState === 4 ) {
61
+ // Response comes in strings most of the time that's why converting it into JSON
62
+ const data = JSON . parse ( this . responseText ) ;
63
+ // console.log(typeof data); // Object
64
+ // console.log(data.followers); // 29
65
+
66
+ // Selecting elements and showing the data using those elements
67
+ const image = document . querySelector ( '#profile-pic' )
68
+ image . src = data . avatar_url
69
+ const para = document . querySelector ( '#followers-count' )
70
+ para . textContent = `GitHub Followers Count : ${ data . followers } `
71
+ }
72
+ }
73
+
74
+ // Making a Call
75
+ xhr . send ( ) ;
76
+ </ script >
77
+ </ body >
78
+ </ html >
0 commit comments