【问题标题】:Load Country/State/City加载国家/州/城市
【发布时间】:2010-04-14 18:31:46
【问题描述】:

我有像国家/州和城市这样的下拉链。有什么办法可以等到人口下降后再继续进行?就像首先加载国家,然后根据国家的选择,然后加载州和城市一样....

function populateLists(listType) {
    // on success do this:
    $.ajax({
    type:"POST",
    url:"Wizard_Using_PageMethod.aspx/GetCountry",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType:"json"}
});

[WebMethod]
public static CountryList GetCountry()
{
    CountryList country = new CountryList();
    ///go to db and get the data
    return country;
}

【问题讨论】:

    标签: jquery ajax


    【解决方案1】:

    你可以这样做

    $('#cb_country').change(function(){
        var id=$(this).val();
        $.get('getCity.php',{id:id},function(data){
            $("#cb_city").html(data);
        });
    });
    

    getCity.php:

    <?php
    require('../conn.php');
    
    $id=$_GET['id'];
    $Q=mysql_query("SELECT * FROM city WHERE CountryID='".$id."' ORDER BY Cityname ASC");
    
    do{
        echo "<option value='".$row['CityID']."'>".$row['CityName']."</option>";
    }
    while($row=mysql_fetch_assoc($Q));
    

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 1970-01-01
      • 2011-03-23
      • 2017-11-11
      • 2011-01-21
      相关资源
      最近更新 更多