I'm not to strong with javascript and am struggling to create a loop through some data passed back from an ajax request.
What I want is for the loop to go through the array ten times and generate a row in a table.
However it doesn't appear to be working. Here is the code in its entirety.
$.getJSON('charts_ajax.php',{a : 'terms'},function(data){
if(data){
var tableTop = '<tbody><tr><th width="5%">#</th><th width="65%">Search Terms</th><th width="15%">Visits</th></tr>';
var si = 1;
$.each(data, function(index, value) {
var tableInner = '<tr><td>1</td><td>' + data[si][0] + '</td><td>307</td></tr>';
si++;
});
var tableBottom = '</tbody></table>';
$('#terms-table').html(tableTop + tableInner + tableBottom);
}
});
Nothing is displaying at all. When I console.log(data) I get:
0: [Terms, Visits]
1: [radio fm, 150]
2: [radio fm grimsby, 25]
3: [radio , 10]
4: [radio fm radio, 9]
5: [radio .co.uk, 9]
6: [grimsby rugby club, 8]
7: [radio radio, 7]
8: [radio radio grimsby, 5]
9: [radio , 5]
10: [radio station, 4]
Am I being a complete noob here?
Cheers in advance guys :)