我试图更新基于国家先前选择选择城市
在警报被正确地从JSON响应显示的选项。
$('#property_country').change(function() {
var selectedCountryId = this.value;
var $city = $('#property_city');
var options = "";
$.ajax({
url: 'Lookup',
method: 'GET',
data: {
action: "getCities",
countryId: selectedCountryId
},
dataType: 'json'
}).done(function(jsonResponse) {
$.each(jsonResponse, function(index, item) {
$.each(item, function(index, item) {
console.log(item.CityId + " " + item.CityName);
options = options + '<option value="' + item.CityId + '"> ' + item.CityName + '</option>';
});
});
alert(options);
$city.html(options);
});
});