Home >
Backend Development >
PHP Tutorial >
Lagging behind the first php+mysql province, city, prefecture level 3 linkage non-refresh menu source code using ajax technology_PHP tutorial
Lagging behind the first php+mysql province, city, prefecture level 3 linkage non-refresh menu source code using ajax technology_PHP tutorial
WBOY
Release: 2016-07-21 15:58:26
Original
834 people have browsed it
Absolutely original Test address: http://www.mlmm.cn/mypage/?name=ceshi
Test page code:
Copy codeThe code is as follows:
php+ajax dynamically generates a drop-down menu
regionss Function code: QUOTE:
Copy code The code is as follows:
//Province and city 3-level linkage drop-down menu function regionss province.city.region function regionss($country="People's Republic of China") { global $db; $i = 1; $text=" "; id="select2" name= "select2" onchange="startRequesta()" style="width:90px;">n"; $text.="
regions.js code:
Copy code The code is as follows:
//var ab = new Array(); var xmlHttp; var xmlHttpa; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function createXMLHttpRequesta() { if (window.ActiveXObject) { xmlHttpa = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttpa = new XMLHttpRequest(); } }
} } } function handleStateChangearea() { eval(xmlHttpa.responseText); } //var ab = new Array();
function startRequesta() { createXMLHttpRequesta(); xmlHttpa.onreadystatechange = handleStateChangea; document.getElementById('select3').options.length = 0; var url = document.form1.select2.value; var qurl = "/regions.php?city="+url+"&time="+new Date().getTime(); xmlHttpa.open("GET", qurl, true); xmlHttpa.send(null); //setTimeout("startRequest()",2000); }
function handleStateChangea() { if(xmlHttpa.readyState == 4) { if(xmlHttpa.status == 200) { var obja = document.getElementBy Id('select3' ); eval(xmlHttpa.responseText); //Write the string returned by the server to the area with the ID select3 on the page
} 🎜> Data Island regions.php page code
Copy code
The code is as follows:< ?php require "common.php";
$result = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province=' $province' ORDER BY cityid"); while($r = $db->fetch_array($result)) { $r[city]=iconv('gb2312','UTF- 8',$r[city]); echo "obj.options[obj.options.length] = new Option('".$r[city]."','".$r[city]. "');n"; $i++; } $resultarea = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid "); $r = $db->fetch_array($resultarea); $city = $r[city]; $resulta = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid"); while($ra = $db->fetch_array($resulta)) { $ra[area]= iconv('gb2312','UTF-8',$ra[area]); echo "obja.options[obja.options.length] = new Option('".$ra[area]."', '".$ra[area]."');n"; $i++; }
} if($city && $province=='' ){ global $db; $i = 1;
$result = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid "); while($r = $db->fetch_array($result)) { $r[area]=iconv('gb2312','UTF-8',$r[ area]); echo "obja.options[obja.options.length] = new Option('".$r[area]."','".$r[area]."');n" ; $i++; } } ?> No changes have been made
This program can be used directly in phpcms3.0. If used elsewhere, please modify it yourself
http://www.bkjia.com/PHPjc/317597.html
www.bkjia.com true
http: //www.bkjia.com/PHPjc/317597.htmlTechArticleAbsolutely original test address: http://www.mlmm.cn/mypage/?name=ceshi test page code : Copy the code as follows: html head metahttp-equiv="Content-Type"content="text/html;charset=gb2...
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