首页 > 解决方案 > 选择选项未更新

问题描述

我正在尝试根据 Country 先前的选择来更新城市的选择

警报正在从 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);
  });

});

标签: jquery

解决方案


推荐阅读