This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4.html
57 lines (54 loc) · 1.78 KB
/
4.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<html lang="en">
<head>
<link rel="stylesheet" href="css/style.css" />
<title>1</title>
</head>
<body>
<main>
<h1>4.html</h1>
<h1>callback hell</h1>
<h1>console main chalo</h1>
<div class="container">
<a href="index.html">home</a>
<a href="1.html">1</a>
<a href="2.html">2</a>
<a href="3.html">3</a>
<a href="4.html">4</a>
<a href="5.html">5</a>
<a href="6.html">6</a>
<a href="7.html">7</a>
<a href="8.html">8</a>
<a href="asyncAwait.html">asyncAwait</a>
<a href="fetchAPI.html">fetchAPI</a>
<a href="placeholderAPI.html">placeholderAPI</a>
<a href="unsplashAPI.html">unsplashAPI</a>
<a href="weatherAPI.html">weatherAPI</a>
</div>
</main>
<script>
const getTodos = (resources, callback) => {
const request = new XMLHttpRequest();
request.addEventListener("readystatechange", () => {
if (request.readyState === 4 && request.status === 200) {
const data = JSON.parse(request.responseText);
callback(undefined, data);
} else if (request.readyState === 4 && request.status === 404) {
callback("could not fetch any data", undefined);
}
});
request.open("GET", resources);
request.send();
};
// this code looks pretty messay, that's why it's callback hell which is very hard to read and maintain
getTodos("./todos/manikangkan.json", (err, data) => {
console.log(data);
getTodos("./todos/priyanshu.json", (err, data) => {
console.log(data);
getTodos("./todos/abhisek.json", (err, data) => {
console.log(data);
});
});
});
</script>
</body>
</html>