Application Example of ajax + php no-refreshing level-2 linkage menu

Source: Internet
Author: User

This php ajax application instance uses ajax + php to call the urban second-level linkage menu, so that we can update the menu in real time based on the database content.

The ajax application example of this php tutorial is an ajax + php call of the second-level urban linkage menu, so that we can update the menu in real time according to the database tutorial content.

<Html>
<Head>
<Title> ajax + php application instance with no additional level-2 linkage menu </title>

<Script language = "webpage effect">
Var xmlhttp = null;

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 ("the browser does not support 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;
}
}
</Script>

<Head>

<Body>
<H3> select a province (autonomous region):

<Form action = "www. bKjia. c0m. php">
<Div>
<Select id = "province" onchange = "sendrequest ()">
<Option value = ""> select a province (autonomous region) </option>
<Option value = "ah"> Anhui </option>
<Option value = "fj"> Fujian </option>
<Option value = "gs"> Gansu </option>
<Option value = "gd"> Guangdong </option>
<Option value = "gx"> Guangxi </option>
<Option value = "gz"> Guizhou </option>
<Option value = "hn"> Hainan </option>
<Option value = "hb"> Hebei </option>
<Option value = "hh"> Henan </option>
<Option value = "hl"> Heilongjiang </option>
</Select>
</Div>
</Form>

<Div id = "city">
</Div>

</Body>
</Html>

Www. bKjia. c0m. php code

<? Php
$ City_arr = array (
"Ah" => "Hefei ",
"Fj" => "Fuzhou ",
"Gs" => "Lanzhou ",
"Gd" => "Guangzhou ",
"Gx" => "Nanning ",
"Gz" => "Guiyang ",
"Hn" => "Haikou ",
"Hb" => "Shijiazhuang ",
"Hh" => "Zhengzhou ",
"Hl" => "Harbin"
);

If (empty ($ _ get ['prov'])
{
Echo iconv ("gb2312", "UTF-8", '<font color = "red"> you have not selected a province (autonomous region) </font> ');
}
Else
{
$ Prov = $ _ get ['prov'];
$ City = $ city_arr [$ prov];
Echo iconv ("gb2312", "UTF-8", 'provincial (Autonomous Region) Capital: '. $ city );
}
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.