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 });
});

ありがとう

4

1 に答える 1