Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const api_url = 'https://www.themealdb.com/api/json/v1/1/categories.php';
- //defining an async function
- // async function getApi(url) {
- // //storing the response
- // const response = await fetch(url);
- // //storing data in form of JSON
- // let data = await response.json();
- // console.log(data.categories);
- // show(data);
- // }
- const get_data = (req, res) => {
- fetch(api_url)
- .then((res) => res.json())
- .then((data) => {
- show(data);
- console.log(data.categories);
- });
- };
- const search_data = (req, res) => {
- }
- function show(data) {
- let tab = `<tr>
- <th>Id</th>
- <th>Category</th>
- <th>CategoryThumb</th>
- <th>Description</th>
- </tr>`;
- // Loop to access all rows
- for (let d of data.categories) {
- tab += `<tr>
- <td>${d.idCategory} </td>
- <td>${d.strCategory}</td>
- <td>${d.strCategoryThumb}</td>
- <td>${d.strCategoryDescription}</td>
- </tr>`;
- }
- // Setting innerHTML as tab variable
- document.getElementById('meals').innerHTML = tab;
- }
- get_data(api_url);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement