链接下拉值在第一个下拉值已更改后不会更改

问题描述:

我正在使用json数据将国家/地区列表,州列表城市列表绑定到下拉列表。我的要求是,基于国家的国家应该改变。基于美国,城市价值应该改变。假设如果我选择印度第一次各自的国家即将到来,但在我更改国家名称下降后,新的值不更新状态下降,我得到了萤火虫国家的正确数据。链接下拉值在第一个下拉值已更改后不会更改

我Jsfile:

$(document).ready(function() { 
    bindData(); 
    BindCountry(); 
    var DropDown1 = $("#ddlCountry"); 
    DropDown1.change(function (e) { 
    var CountryCode = DropDown1.val(); 
    if (CountryCode >= 1) { 

     GetStates(CountryCode); 

    } 

    }); 

}); 


function BindCountry() { 

var Dropdown1 = $("#ddlCountry"); 
$.ajax({ 
    type: "POST", 
    url: location.pathname + "/GetCountry", 
    data: "{}", 
    contentType: "application/json;charset=utf-8", 
    datatype: "json", 
    success: function (response) { 
     var country = response.d; 
     $.each(country, function (index, country) { 
      Dropdown1.append('<option value="' + country.CountryCode + '">' + country.Country + '</option>'); 

     }); 
    }, 
    failure: function (msg) { 
     alert(msg); 

     } 

    }); 

    } 


function GetStates(Coun_code) { 
    var DdlState = $("#ddlState"); 
    $.ajax({ 
    type: "POST", 
    url: location.pathname + "/GetStates", 
    data: "{'CountryCode':'" + Coun_code + "'}", 
    contentType: "application/json;charset=utf-8", 
    datatype: "json", 
    success: function (response) { 
    var state = response.d; 
    $.each(state, function (index, state) { 
    DdlState.append('<option value="' + state.StateCode + '">' + state.StateName + '</option>'); 

     }); 

     }, 
    failure: function (msg) { 

    alert(msg); 

    } 


    }); 

} 

是否有任何自动过帐回来就好asp.net属性是这里的JavaScript?

+0

是否有在控制台的任何错误?那是打法? –

+0

一切看起来不错,我得到正确的数据......正如我提到的问题,它是第一次正常工作。但第二次更改国名后,各自的变化并不反映在剩余的2个下拉菜单 –

这可能发生,因为我已经添加在你的国家的部分返回假的,所以删除this.i没有试过

 $(document).ready(function() { 
      bindData(); 
      BindCountry(); 
      var DropDown1 = $("#ddlCountry"); 
      DropDown1.change(function (e) { 
      var CountryCode = DropDown1.val(); 
      if (CountryCode >= 1) { 

       GetStates(CountryCode); 

      } 

      }); 

     }); 


     function BindCountry() { 

     var Dropdown1 = $("#ddlCountry"); 
     $.ajax({ 
      type: "POST", 
      url: location.pathname + "/GetCountry", 
      data: "{}", 
      contentType: "application/json;charset=utf-8", 
      datatype: "json", 
      success: function (response) { 
       var country = response.d; 
       $.each(country, function (index, country) { 
        Dropdown1.append('<option value="' + country.CountryCode + '">' + country.Country + '</option>'); 

       }); 
      }, 
      failure: function (msg) { 
       alert(msg); 

       } 

      }); 
     t 
      } 


     function GetStates(Coun_code) { 
      var DdlState = $("#ddlState"); 
      $.ajax({ 
      type: "POST", 
      url: location.pathname + "/GetStates", 
      data: "{'CountryCode':'" + Coun_code + "'}", 
      contentType: "application/json;charset=utf-8", 
      datatype: "json", 
      success: function (response) { 
      var state = response.d; 
      $.each(state, function (index, state) { 
      DdlState.append('<option value="' + state.StateCode + '">' + state.StateName + '</option>'); 

       }); 

       }, 
      failure: function (msg) { 

      alert(msg); 

      } 


      }); 
     return false; 
     } 

    Hope this will work. 
+0

为什么这个工作,你有什么改变? –

+0

不工作!!!!!!!! –