I am trying to populate a drop down using with the following JSON data:
[
{
"id": "1",
"name": "Unknown"
},
{
"id": "2",
"name": "Chrome"
},
{
"id": "3",
"name": "Firefox"
},
{
"id": "4",
"name": "Internet Explorer"
},
{
"id": "5",
"name": "Edge"
},
{
"id": "6",
"name": "Safari"
},
{
"id": "7",
"name": "Mobile Chrome"
},
{
"id": "8",
"name": "Mobile Safari"
},
{
"id": "9",
"name": "Opera"
}
]
Here is my code:
$(document).ready(function () {
$.getJSON("http://www.randyconnolly.com/funwebdev/services/visits/browsers.php", function(results){
var $el = $("#filterBrowser");
$el.empty(); // remove old options
$el.append($("<option></option>")
.attr("value", '').text('Please Select'));
$.each(results, function (index, value) {
$el.append($("<option></option>")
.attr("value", value).text(value));
});
});
});
The dropdown is being populated incorrectly, and it's returning
[object Object]
rather than "Unknown,Chrome,Firefox,Internet Explorer, and so on.