加载国家/国家/城市 [英] Load Country/State/City

查看:119
本文介绍了加载国家/国家/城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有连锁下拉像国家/国家和本市的。有没有什么办法可以等到下拉人口然后再继续吗?就像第一次加载的国家​​,然后根据一个国家的选择,然后加载状态和相同的城市......

 函数populateLists(listType){
    //成功做到这一点:
    $阿贾克斯({
    键入:POST,
    网址:Wizard_Using_PageMethod.aspx / GetCountry
    数据: {},
    的contentType:应用/ JSON的;字符集= UTF-8,
    数据类型:JSON}
});

[WebMethod的]
公共静态CountryList GetCountry()
{
    CountryList国家=新CountryList();
    ///去DB和获取数据
    返回的国家;
}
 

解决方案

您可以不喜欢这样

  $('#cb_country')。改变(函数(){
    VAR ID = $(本).VAL();
    $获得('getCity.php',{ID:ID},功能(数据){
        $(#cb_city)的HTML(数据);
    });
});
 

getCity.php:

 < PHP
需要('../ conn.php');

的$ id = $ _ GET ['身份证'];
$ Q =请求mysql_query(SELECT * FROM城市,CountryID ='的$ id。'ORDER BY城市名ASC);

做{
    回声<期权价值='$行['CityID'。>中$行['城市名']。< /选项>中;
}
而($行= mysql_fetch_assoc($ Q));
 

I have chain of drop down like Country / state and City. Is there is any way to wait until the drop down population then proceed further? like first load the country and then based on the select of an country then load the state and same as city....

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

解决方案

You may do like this

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

这篇关于加载国家/国家/城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆