如何进行多个ajax调用?

我有5个下拉框,如(国家,州,区,镇,街)。
当我选择国家时,我正在加载属于该国家的(州,区,镇,街道)。

我的问题是,我正在为此制作4个单独的ajax调用。

$('#Country').change(function(){ var procemessage = " Please wait..."; $("#State").html(procemessage).show(); var CountryId = $(this).val(); $.ajax({ url: '../Home/LoadStateForCountry?CountryId=' + CountryId, success: function (result) { var markup = ""; if (result.length < 1) { markup = "--Nothing to Select--"; } else { data = result; markup = "--Select--"; for (var x = 0; x < data.length; x++) { markup += "" + data[x].DisplayText + ""; } } $("#State").html(markup).show(); }, error: function (result) { } }); }); $('#Country').change(function(){ //Load district }); $('#Country').change(function(){ //Load town }); $('#Country').change(funstion(){ //Load street }); 

这样做是对的。 或者无论如何都要立即调用它。
我是MVC的新手。 所以请指导我。

您可以简单地使用ajax调用来加载国家/地区状态

 $('#Country').change(funstion(){ BindStateDropDown(); BindDistrictDropDown(); BindTownDropDown(); BindStreetDropDown(); }); 

或者你可以做的是回拨一个ajax调用你可以再做一个ajax调用让我们说在LoadState的回调你可以再加一个ajax调用来加载区。

 $.get("URLToLoadState",{CountryId:CountryId },function(data){ BindDistrict() }); 

在回电区,你可以去镇,然后街。

或另一种选择是,

您可以为所有这些实体创建包装类,例如

 public class LocationModel { public List StateList{get;set;} public List StateList{get;set;} public List StateList{get;set;} public List StateList{get;set;} } 

在更改国家/地区时,您可以通过一次通话获得所有collections

 $('#Country').change(funstion(){ $.get("UrlToLoadLocations",{CountryId:CountryId},function(data){ BindStateDropDown(data.StateList); BindStateDropDown(data.DistrictList); BindStateDropDown(data.TownList); BindStateDropDown(data.StreetList); }); 

});