【发布时间】:2014-03-29 10:17:22
【问题描述】:
我正在使用 json 数据将国家列表、州列表城市列表绑定到下拉列表。我的要求是应该根据国家/地区进行更改。基于美国,城市价值应该改变。假设如果我第一次选择印度各个州,但是在我更改国家下拉列表中的国家名称后,新值不会在状态下拉列表中更新,我在 firebug 中获得了正确的州数据。
我的 Js 文件:
$(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);
}
});
}
javascript中有没有像asp.net这样的Autopost back属性??
【问题讨论】:
-
控制台有错误吗?是打法吗?
-
一切似乎都很好,我得到了正确的数据...正如我在问题中提到的,它第一次运行良好。但是在第二次更改国家/地区名称后,相应的更改并未反映在剩余的 2 个下拉菜单中
标签: jquery