I am trying to populate a blank table with data returned from Ajax request. The table populates inside the correct columns, but all the data data is clumped up (in a long string) and all the interest rate data is clumped up (in a long string). Despite this the Console.log()
line works perfect and shows each item, enumerated, all on seperate lines.
My code is below:
HTML
<table id="table" border="1">
<tr>
<th>Date</th>
<th>Value</th>
</tr>
<tr>
<td id='col1'></td>
<td id='col2'></td>
</tr>
</table>
Javascript/jQuery
$.getJSON("api", function(data) {
for (var x =1; x <= data.count -1 ; x++){
$("#col1").append(data.observations[x].date);
$("#col2").append(data.observations[x].value);
console.log(x, data.observations[x].date, data.observations[x].value);
}
})
How can I rewrite it so that each date and interest rate is on a seperate row. Example: row1:date1 and value1, row2: date2 and value2, etc..
P.S. Answer should include $.getJSON(api, data)
and
NOT included $.parseJSON(data)
or $.each(data))
or success: function (data))
` after each "cell" – DIEGO CARRASCAL Oct 17 '17 at 19:56