OiO.lk Blog HTML why json file value is not displayed (javascript)
HTML

why json file value is not displayed (javascript)


  <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