Am trying to populate static content on my web app from a database call which returns a JSON list of elements that I then would like to make the Option 1 populate with..
JSON returned:
{id: 0, categoryName: "General Discussion"},
.
.
.
{id: 7, categoryName: "Cleaning and Repairs"}
My call:
$.get("http://localhost:8080/cc/sc/cat").done(function(categories) {
var catList = document.getElementById("categories");
var option = document.createElement("option");
for (category in categories){
console.log("value: " + categories[category].categoryName);
option.text = categories[category].categoryName;
catList.add(categories[category].categoryName);
}
});
The HTML content
<select id="categories" class="form-control"></select>
The error:
(index):116 Uncaught TypeError: Failed to execute 'add' on 'HTMLSelectElement': The provided value is not of type '(HTMLOptionElement or HTMLOptGroupElement)'
at Object.<anonymous> ((index):116)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)
Any help is appreciated.