首页 > 代码库 > 补2017.5.14

补2017.5.14

三级联动

<script src="http://www.mamicode.com/jquery-1.8.2.min.js"></script>
<script src="http://www.mamicode.com/Area.js"></script>
</head>

<body>
<h1>显示数据</h1>

<select id="sel1">

</select>
<select id="sel2">

</select>
<select id="sel3">

</select>

 

</body>
<script type="text/javascript">
$(document).ready(function(e) {

//异步AJAX
//异步和同步
var pcode = "0001";

$.ajax({
async:false,
url:"chuli1.php",
data:{pcode:pcode},
   type:"POST",
dataType:"TEXT",
complete: function(){},
beforeSend: function(){},
error: function(){},
success: function(data){
var hang = data.split("|");
var str = "";
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
str = str +"<option value=http://www.mamicode.com/‘"+lie[0]+"‘>"+lie[1]+"</option>";
}
$("#sel1").html(str);

}
});

});
</script>
<script type="text/javascript">
$(document).ready(function(e) {

//异步AJAX
//异步和同步
var pcode = "11";

$.ajax({
async:false,
url:"chuli2.php",
data:{pcode:pcode},
   type:"POST",
dataType:"TEXT",
complete: function(){},
beforeSend: function(){},
error: function(){},
success: function(data){
var hang = data.split("|");
var str = "";
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
str = str +"<option value=http://www.mamicode.com/‘"+lie[0]+"‘>"+lie[1]+"</option>";
}
$("#sel2").html(str);

}
});

});
</script>
<script type="text/javascript">
$(document).ready(function(e) {

//异步AJAX
//异步和同步
var pcode = "1101";

$.ajax({
async:false,
url:"chuli3.php",
data:{pcode:pcode},
   type:"POST",
dataType:"TEXT",
complete: function(){},
beforeSend: function(){},
error: function(){},
success: function(data){
var hang = data.split("|");
var str = "";
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
str = str +"<option value=http://www.mamicode.com/‘"+lie[0]+"‘>"+lie[1]+"</option>";
}
$("#sel3").html(str);

}
});

});

注意好同步和异步。

chuli1的代码

//给我一个父级代号,返回该父级代号下所有的子地区

 

<?php
$pocde=$_POST["pcode"];
require "./DBDA.class.php";
$db = new DBDA();

$sql = "select areacode,areaname from chinastates where parentareacode=‘{$pocde}‘";

echo $db->strquery($sql);

 

补2017.5.14