2010-04-14 124 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));