I'm trying to fetch data from an external JSON file into the inner HTML but I can't understand what the problem is. Data is smoothly displayed through the console but nothing is showing up on the HTML page.
Everything looks perfect :(
Please help me identify and resolve this issue
<!DOCTYPE html>
<html>
<body>
<div class="container">
<table class="table table-stripped">
<thead>
<tr>
<th>Player ID</th>
<th>Player Name</th>
<th>Player Country</th>
</tr>
</thead>
<tbody id="data">
</tbody>
</table>
<script>
fetch("http://localhost/test.json").then (
res=>
{
res.json().then
(
data=>
{
console.log(data);
if(data.length >0)
{
var temp = "";
//Beginning of the For loop
data.forEach((u)=>{
temp +="<tr>";
temp +="<td>"+u.Id+"</td>";
temp +="<td>"+u.Name+"</td>";
temp +="<td>"+u.Country+"</td>"
temp += "</tr>";
})
// --- End of the For Loop
document.getElementById("data").innerHTML = temp; //The #tbody ID
}
}
)
}
)
</script>
</body>
</html>