I am trying to populate a select box based on JSON data returned from my ASP page: http://accdbmgr-001-site1.etempurl.com/ajax.asp
This is the data returned from the Server:
{
"data": [{
"Lastname": "Roussel",
"Firstname": "Donald"
}, {
"Lastname": "Sabourin",
"Firstname": "Manon"
}, {
"Lastname": "Kelly",
"Firstname": "Bruce"
}]
}
However, for some reason it just doesn't seem to be able to add my JSON data into the select box. I'd like for the options to appear as: Lastname, FirstName
<div id="test"></div>
<form>
<select id="select1"></select>
</form>
$(document).ready(function() {
$.get('http://accdbmgr-001-site1.etempurl.com/ajax.asp', {
category: 'client',
type: 'premium'
}, function(data) {
alert("success")
//$("#test").html(data)
var obj = JSON.parse(data);
for (i in obj) {
$('#select1').append(new Option(obj[i].Firstname, obj[i].Lastname));
}
});
});
for (i in obj.data)${obj[i].Firstname}, ${obj[i].Lastname}because the first one is the display one and the second one is the value behind, so they will not appear both as you expect.