Team I am trying to fetch a URL which returns a array within a json, so I can make a table..
I think the array is breaking the code, anyone has any tips?
getData.onclick = () => {
fetch('https://xxx.xxx.com/trackingsensor', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
mode:"cors"
}
)
.then(res => res.text())
.then((out) => {
let jsonData = JSON.parse(out);
console.log(jsonData);
for (let i = 0; i < jsonData.Items[0].length; i++) {
let earnings = jsonData.Items[0][i];
console.log(earnings);
myData.innerHTML +=
"<tr><td>" + earnings.TempMax + "</td>" +
"<td align='right'>" + earnings.TempControl + "</td>" +
"<td align='right'>" + earnings.ProductID + "</td>" +
"<td align='right'>" + earnings.Description + "</td></tr>";
};
})
.catch(err => console.error(err));
}
<button type="button" id="getData">Get data</button>
<table>
<thead>
<tr>
<th>TempMax</th>
<th>TempControl</th>
<th>ProductID</th>
<th>Description</th>
</tr>
</thead>
<tbody id="myData">
<tbody>
</table>
adding a for with array but no luck.




