Home  >  Article  >  Backend Development  >  ajax+php无刷新二级联动菜单的应用实例_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 10:57:521017browse

本款php ajax应用实例是一款利用ajax+php调用城市二级联动菜单,这样我们可以实时的根据数据库内容更新了。

本款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 = "www.bKjia.c0m.php";
    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;
    }
}


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


   

   
   



www.bKjia.c0m.php代码

$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);
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632055.htmlTechArticle本款php ajax应用实例是一款利用ajax+php调用城市二级联动菜单,这样我们可以实时的根据数据库内容更新了。 本款php教程 ajax应用实例是一款...
Statement:
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