Display JSON Object in Drop Down List
Suppose my AJAX call brings back the following json objects from the backend:
[{"FName":"Jane","LName":"Doe", "ID":"ABC123"},
{"FName":"Joe","LName":"Bloe", "ID":"XYZ456"}
]
Below is my AJAX call but I have not been able to display the JSON contents in a drop down list.
- var custNames= $("#Customers"); //Drop Down List ID
- $.ajax({
- url: 'http://localhost:32388/api/service',
- type: 'GET',
- dataType: 'json',
- contentType: 'application/json; charset=utf-8',
- success: function (data) {
- custNames.append($('</option>', { value: -1, text: 'Select a customer' }));
- $(data).each(function (index, item) {
- custNames.append($('</option>', { value:item.FName + ' ' + item.LName, text:item.FName + ' ' + LName}));
- custNames.append($('</option>', { value:item.ID, text:item.ID}));
- });
- }
- });
Please point out where I went wrong in my code, thanks.