Currently, I'm facing an issue where the code I'm using takes about 10 seconds to run on Chrome and around 2 minutes on IE11, which is the primary browser it will be used with.
for (var key in dict) {
if (dict.hasOwnProperty(key)) {
combo.innerHTML += "<option value=\"" + dict[key] + "\">" + key + "</option>";
}
}
I came across a tutorial at , recommending the use of ajax for dealing with larger datasets. However, the definition of 'large' is not clear - could it mean 100 items or 100,000 items?
var request = new XMLHttpRequest();
request.onreadystatechange = function(response) {
if (request.readyState === 4) {
if (request.status === 200) {
var jsonOptions = JSON.parse(request.responseText);
jsonOptions.forEach(function(item) {
var option = document.createElement('option');
option.value = item;
dataList.appendChild(option);
});
} else {
console.log("Failed to load datalist options");
}
}
};
request.open('GET', 'html-elements.json', true);
request.send();
I've been trying to adapt this approach for a dictionary by replacing request.responseText
with
JSON.parse(JSON.stringify(dict));
. However, I'm encountering issues as the data is not stored in a file, making it difficult to make the request from the server. Any suggestions on how to proceed? And if a DataList isn't suitable for this purpose, what alternative would you recommend?
Appreciate any advice in advance.