-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetching.html
More file actions
56 lines (51 loc) · 1.42 KB
/
fetching.html
File metadata and controls
56 lines (51 loc) · 1.42 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="submit">Submit</button>
<div id="data"></div>
</body>
</html>
<script>
const url = "https://my-json-server.typicode.com/FreSauce/json-ipl/data";
fetchData();
async function fetchData() {
const response = await fetch(url); //kaato
var data = await response.json(); //gholo
console.log(data.length); // lagalo
data.sort(function (a, b) {
return a.NRR - b.NRR;
});
var list = `<table><tr>
<th>No</th>
<th>Team</th>
<th>Matches</th>
<th>Won</th>
<th>Lost</th>
<th>Tied</th>
<th>NRR</th>
<th>Points</th>
</tr>
<tbody>`;
var list;
for (var i = 0; i < data.length; i++) {
list += `<tr>
<td>${data[i].No}</td>
<td>${data[i].Team}</td>
<td>${data[i].Matches}</td>
<td>${data[i].Won}</td>
<td>${data[i].Lost}</td>
<td>${data[i].Tied}</td>
<td>${data[i].NRR}</td>
<td>${data[i].Points}</td>
</tr>`;
}
list += `</tbody></table>`;
document.getElementById("data").innerHTML = list;
}
</script>