<div>
<script type="text/javascript">
$(document).ready(function(){
$('#selectstate').change(function() {
window.location = "dropexmpl.php?stateval=" + $(this).val();
});
$('#selectcity').change(function() {
window.location = "dropexmpl.php?cityval=" + $(this).val();
});
});
</div>
</script>
</head>
<body >
<div>
<?php
//state drop down
echo "<td"." id="."id_sel_state".">";
$con=mysql_connect("localhost","root","");
mysql_select_db("data_filter",$con);
$query=("SELECT id,state_name FROM state_details ");
$result = mysql_query ($query);
echo "<label id='statelab'>Select state : </label>"."<select name='filterstate'id='selectstate' onchange='getstateval()'>";
while ($nt = mysql_fetch_array($result)){
echo "<option value='".$nt['id']."'>".$nt['state_name']."</option>";
}
echo "</select>";
//city drop down
$statestrval= $_GET['stateval'];
echo "<td id='id_sel_city'>";
$query1="SELECT id,state_id,city_name FROM city_details WHERE state_id=".$statestrval.""; $result1 = mysql_query ($query1);
echo "<label>Select city : </label>"."<select name='filtercity' id='selectcity' >";
while ($nt = mysql_fetch_array($result1)){
echo "<option value='".$nt['id']."'>".$nt['city_name']."</option>";
}
echo "</select>";
//Zone drop down
$citystrval= $_GET['cityval'];
echo "<td id="."id_sel_zone".">";
$query2="SELECT id,city_id,zone_area FROM zone_details WHERE city_id=".$citystrval."";
$result2 = mysql_query ($query2);
echo "<label>Select industry zone : </label>"."<select name='filterzone' id='selectzone'>";
while ($nt = mysql_fetch_array($result2)){
echo "<option value='".$nt['id']."'>".$nt['zone_area']."</option>";
}
echo "</select>";
mysql_close($con);
?>
</div>
</form>
</body>
</html>
在这里,我使用了 3 个下拉状态城市和区域。它可以工作,但是当使用 window.location 代码重新加载页面时,它会向我显示具有刷新效果的页面,它是如何使用 ajax 解决的。it should be like when i select the state is should be shows city list related to that state.when city is selected it should be shows the zone related to that city .but problem is when i go to select the city it change the state list当我选择区域时,它会因为重新加载页面而更改城市列表,我该如何解决这个问题。