OiO.lk Blog javascript Why JSON file value is not displayed?
javascript

Why JSON file value is not displayed?


  <script>
        // Fetch JSON data
        fetch('dat.json')
               .then(response => response.json())
            .then(data => {
                const tbody = document.querySelector('#dataTable tbody');
                data.forEach(item => {
                    const row = document.createElement('tr');
                    row.innerHTML = `
                        <td>${item.name}</td>
                        <td>${item.age}</td>
                        <td>${item.city}</td>
                    `;
                      tbody.appendChild(row);
                });
            })
                .catch(error =>console.error('Error fetching the data:', error));
    </script>

Why JSON file value is not displayed? The code I took from ChatGPT. I tried vscode and notepad+++ too, none of them work.



You need to sign in to view this answers

Exit mobile version