Home > php教程 > php手册 > ajax+php无刷新二级联动菜单的应用实例

ajax+php无刷新二级联动菜单的应用实例

WBOY
Release: 2016-05-25 16:57:42
Original
1234 people have browsed it
本款php ajax应用实例是一款利用ajax+php调用城市二级联动菜单,这样我们可以实时的根据数据库内容更新了。
 代码如下 复制代码



ajax+php无刷新二级联动菜单的应用实例

function getxmlhttprequest()
{
    var xmlhttp=null;
    try
    {
        xmlhttp = new xmlhttprequest();
    }
    catch(e)
    {
        try
        {
            xmlhttp = new activexobject("msxml2.xmlhttp");
        }
        catch (e)
        {
            try
            {
                xmlhttp = new activexobject("microsoft.xmlhttp");
            }
            catch(e)
            {
                xmlhttp = false;
            }           
        }
    }

return xmlhttp;
}

function sendrequest()
{
    var prov_name = document.getelementbyid("province").value;

    if((prov_name == null) || (prov_name == ""))
        return;
   
    xmlhttp = getxmlhttprequest();
    if(xmlhttp == null)
    {
        alert("浏览器不支持xmlhttprequest!");
        return;
    }

    var url = "http://www.phprm.com";
    url = url + "?prov=" + prov_name;

    xmlhttp.open("get", url, true);
    xmlhttp.onreadystatechange = updatepage;
    xmlhttp.send(null);
}

function updatepage()
{
    if(xmlhttp.readystate == 4 && xmlhttp.status == 200)
    {
        var response = xmlhttp.responsetext;
        document.getelementbyid("city").innerhtml = response;
    }
}


请选择一个省(自治区):


   

   
   



http://www.phprm.com代码

 代码如下 复制代码

$city_arr = array(
"ah"=>"合肥",
"fj"=>"福州",
"gs"=>"兰州",
"gd"=>"广州",
"gx"=>"南宁",
"gz"=>"贵阳",
"hn"=>"海口",
"hb"=>"石家庄",
"hh"=>"郑州",
"hl"=>"哈尔滨"
);

if(empty($_get['prov']))
{
    echo iconv("gb2312","utf-8",'您没有选择省(自治区)');
}
else
{
    $prov = $_get['prov'];
    $city = $city_arr[$prov];
    echo iconv("gb2312","utf-8",'所选省(自治区)省会(首府)为:'.$city);
}
?>



文章网址:

随意转载^^但请附上教程地址。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template