I need to populate a select item with the values that I get from an ajax call, I return such values as a json array. With the code below, the select is created without any options.
$.ajax({
type: "GET",
url: "/wp-content/gta/search_airport.php",
data: {city: t_city}
}).done(function(resp){
var sel = $('<select name="airport" id="slt">').appendTo('#pick_type');
$.each(resp, function() {
$.each(this, function(k, v) {
$('<option>').val(k).text(v).appendTo('#slt');
});
});
});
Example json array
[{"name":"Los Angeles","code":"LAX"},{"name":"San Francisco","code":"SFO"}]
I would like the options to be something like <option value="LAX">Los Angeles</option>