1
var objCountries = [];
var objSearchCountry = new Object();
objSearchCountry.CountryName = $("#txtCountry").val();
$.ajax({
type: "POST",
url: "db.php?GetCountryList",
data: {data:[]},
dataType: "json",
async:false,
success: function(response)
{
if(response.IsError)
alert(response.ErrorMessage);
else
objCountries = response;
},
error:function(response)
{
alert("Error: " + response.responseText);
}
});
var newObjCountry = [];
for (var indexCountry in objCountries)
newObjCountry.push(objCountries[indexCountry].CountryName);
$("#txtCountry").autocomplete({ source: newObjCountry });
当我选择任何一个国家
,我想它的ID,这样我可以通过这个ID,在城市获得相关的城市。
$("#txtCountry").blur(function()
{
//for city
var objCities = [];
var objSearch = new Object();
objSearch.city_name = $("#txtCity").val();
$.ajax({
type: "POST",
url: "db.php?GetCityList",
data: {data:[]},
dataType: "json",
async:false,
success: function(response)
{
if(response.IsError)
alert(response.ErrorMessage);
else
objCities = response;
},
error:function(response)
{
alert("Error: " + response.responseText);
}
});
var newObj = [];
for (var index in objCities)
newObj.push(objCities[index].city_name);
$("#txtCity").autocomplete({ source: newObj });
});
感谢
您可以使用$( “#txtCountry”)。VAL() ;获取Country val并将其传递给您的GetCityList方法。 –
已尝试但无法运行.. :( –
您不会在任何地方存储国家ID。创建自动填充时,它只包含国家/地区名称。您需要使用select元素。 – Archer