Skip to content

Commit e8991fa

Browse files
committed
API requests
1 parent 099f16a commit e8991fa

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

09_advance_one/ApiRequest.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
</head>
8+
<body style = "background-color: #212121; color:#fff;">
9+
0 UNSENT Client has been created. open() not called yet
10+
1 OPENED open() has been called.
11+
2 HEADERS_RECEIVED send() has been called, and headers and status are available
12+
3 LOADING Downloading; responseText holds partial data.
13+
4 DONE The operation is complete.
14+
</body>
15+
<script>
16+
const requestUrl = 'https://api.github.com/users/kanaklatwal'
17+
const xhr = new XMLHttpRequest();
18+
xhr.open('GET', requestUrl)
19+
xhr.onreadystatechange = function(){
20+
console.log(xhr.readyState);
21+
if(xhr.readyState === 4){
22+
//Whenever the response come most of the time it comes in string
23+
const data = JSON.parse(this.responseText);
24+
console.log(typeof data);
25+
console.log(data);
26+
console.log(data.followers);
27+
//console.log(this.responseText);
28+
}
29+
}
30+
31+
// console.log -> debugging tool/ debugger of browser devloper tool/ it inject runtime javascript
32+
33+
// console.log("HERE");
34+
xhr.send();
35+
</script>
36+
</html>

0 commit comments

Comments
 (0)