I am currently developing a webpage that interacts with a CGI backend. While the CGI backend is functioning well, my limited knowledge of JavaScript is making it hard for me to manage the results retrieved from AJAX JSON requests.
Here's what I have:
A JavaScript function sends queries to the CGI.
The CGI responds with a JSON array.
{
"ARRAY": [
{
"line": "1",
"numbers": "12321",
"var": "12321",
"var2": "12321"
},
{
"line": "2",
"numbers": "-1",
"var": "12320",
"var2": "6160"
}
]
}
The 'line', 'numbers', 'var', and 'var2' data must be displayed in separate cells of a table.
<table>
<tr>
<th>line</th><th>numbers</th><th>var</th><th>var2</th>
</tr>
<tr>
<td>ARRAY[0].line</td><td>ARRAY[0].numbers</td><td>ARRAY[0].var</td><td>ARRAY[0].var2</td>
</tr>
<tr>
<td>ARRAY[1].line</td><td>ARRAY[1].numbers</td><td>ARRAY[1].var</td><td>ARRAY[1].var2</td>
</tr>
</table>
My current issue is:
I don't know beforehand how many objects will be stored inside the array. In this example, there are 2, but there could be up to 20 or more. I am open to modifying my JSON structure if necessary. How can I create a loop that iterates through all the objects in the array?