2010-04-14 97 views
2

我有像国家/州和城市的下拉链。是否有任何方法可以等到下降人口继续进行下去?像第一次加载的国家,然后根据选择的国家,然后加载状态,并同市....加载国家/州/市

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

回答

3

你可以做这样的

$('#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));