Skip to content

Commit 98d6ba5

Browse files
authored
modified
1 parent c44809f commit 98d6ba5

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

50.8 KB
Loading
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,4 @@ <h1> Hello...... </h1>
7979
})
8080

8181

82-
83-
8482
</script>

Basics/22_apiRequest.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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>API Request</title>
7+
</head>
8+
<body style="background-color: black;">
9+
10+
</body>
11+
12+
<script>
13+
const requestURL = 'https://api.github.com/users/pkprashantkr'
14+
const xhr = new XMLHttpRequest()
15+
xhr.open('GET', requestURL)
16+
17+
// continuously monitoring state
18+
xhr.onreadystatechange = function(){
19+
console.log(xhr.readyState); // getting state
20+
if(xhr.readyState == 4){
21+
// If we will try to access things within data then, this will give undefined as we get string from the reponse of url. So, can't access like objects
22+
const data = JSON.parse(this.responseText) // JSON.parse converts the string into JSON data.
23+
console.log(`No. of followers is: ${data.followers}`);
24+
console.log(`Avatar is: ${data.avatar_url}`);
25+
console.log(data);
26+
}
27+
}
28+
console.log("Here");
29+
xhr.send() // to send the request
30+
31+
</script>
32+
33+
</html>

0 commit comments

Comments
 (0)