I recently modified my JSON array and it seems to have caused some issues with the code. The change I made was converting it into a two-dimensional array, possibly?
JS
$(function() { ...
...$.ajax({
type: "POST",
url: 'updatefilters',
dataType: 'json',
data: { filters: filters, page: page },
success: function(data){
html = "<table class='board'>";
html += "<table class='board'>";
html += " <tr>";
html += " <th width='7.5%'>Author</th>";
html += " <th width='5%'><img src='../img/board/icons/category_icon.png' alt='category_icon'/></th>";
html += " <th width='5%'>Tag</th>";
html += " <th width='50%'>Subject</th>";
html += " <th width='7.5%'>Replies/Views</th>";
html += " <th width='15%'>Last Post</th>";
html += " </tr>";
for (i=0 ; i < data[threads].length ; i++)
{
html += "<tr><td>" + data[threads][i].username + "";
}
html += "</table></div>";
$('#board').html(html);
} ...
The JSON data that was returned is as follows:
{"0":"blurb","filter":["blurb"],"threads":[{"thread_id":"234","owner_id":"3","subject":"Blurb(?) is in Heavy Development!","body":"Please be aware that this site is still in heavy development. What you are viewing here is a prototype, not meant to be seen as a final product. if you have comments or suggestions, please send it to <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03716a60687a6e6e3043646e626a6f2d606c6e">[email protected]</a>\n\nThank You!","timestamp":"2012-05-11 08:02:28","replystamp":"2012-05-11 08:02:28","last_post_id":"3","slug":"234-blurb-is-in-heavy-development","replies_num":"0","views":"1","username":"guest"}]}
I am encountering an issue where data[threads] appears to be undefined in the FOR loop within the JS code. Can anyone suggest why data[threads][i] isn't functioning properly?