I'm trying to list data from a JSON source.
I loop the data in a $.each, and display it using append.
var result = JSON.parse(response);
if(result.count != 0) {
$(".modal").find("#search-results").html("<p>" + result.count + " result(s) found:</p>");
var list = $(".modal").find("#search-results").append("<div class=\"list-group dbsearch-list-group\"></div>").find('div');
$.each(result.results, function(index, value) {
var link = list.append('<a href="javascript:;" class="list-group-item p-0 list-group-item-action" id="autosearch" data-id="' + value.itemid + '" data-instantclose="true"></a>').find('a');
var col = link.append('<div class="row"></div>').find('div');
col.append('<div class="col-sm py-0 col-md-auto"><img src="' + value.icon + '" class="dbsearch-icon" /></div>');
col.append('<div class="col-sm py-0 align-self-center">' + value.title + '</div>');
});
} else {
$(".modal").find("#search-results").html("<p>No results found.</p>");
}
For some odd reason, it outputs an error after a couple of loops:
jquery-3.3.1.min.js:2 Uncaught RangeError: Maximum call stack size exceeded
I've Googled the error and they say it's caused by an infinite loop. The JSON response entries can be quite long, around 300 items.
Even then, it shouldn't really output this if I'm correct. Why is this happening?
