-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.html
42 lines (36 loc) · 845 Bytes
/
new.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
<!DOCTYPE html>
<html>
<head>
<title>Chirag Rocks</title>
</head>
<body>
<script type="text/javascript">
function hitApi(url, callback) {
var req = new XMLHttpRequest();
req.addEventListener('load', onLoad);
req.addEventListener('error', onFail);
req.addEventListener('abort', onFail);
req.open('GET', url);
req.send();
function onLoad(event) {
if (req.status >= 400) {
onFail(event);
} else {
var json = JSON.parse(this.responseText);
callback(null, json);
}
}
function onFail(event) {
callback(new Error('...'));
}
}
hitApi('https://serchirag.github.io/languagesAPI/hi.json', function(error, data) {
if (error) {
console.log('there was an error', error);
} else {
console.log(data);
}
});
</script>
</body>
</html>