-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
73 lines (56 loc) · 1.56 KB
/
api.js
File metadata and controls
73 lines (56 loc) · 1.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Make an HTTP request to the API
//date = "2023/02/24"
//fullApi = link.concat(date)
// api url
url =
"https://daltonschool.flikisdining.com/menu/api/weeks/school/dalton-school/menu-type/lunch/2023/02/24";
// Defining async function
function getapi() {
// Storing response
fetch(url, { mode: 'no-cors'})
.then(res => res.text())
.then(json => console.log(json))
// Storing data in form of JSON
// var data = await response.json();
// console.log(data);
// if (response) {
// hideloader();
// }
// show(data);
}
// Calling that async function
getapi();
// Function to hide the loader
function hideloader() {
document.getElementById('loading').style.display = 'none';
}
// Function to define innerHTML for HTML table
function show(data) {
let tab =
`<tr>
<th>Name</th>
<th>Office</th>
<th>Position</th>
<th>Salary</th>
</tr>`;
// Loop to access all rows
for (let r of data.list) {
tab += `<tr>
<td>${r.name} </td>
<td>${r.office}</td>
<td>${r.position}</td>
<td>${r.salary}</td>
</tr>`;
}
// Setting innerHTML as tab variable
document.getElementById("menu_type_id").innerHTML = tab;
}
// fetch(link)
// .then(response => response.json())
// .then(data => {
// // Update the HTML content with the API data
// const apiData = document.getElementById("rounded_nutrition_info");
// apiData.innerHTML = data;
// console.log
// })
// .catch(error => console.error(error));