使用jQuery Ajax
yourfile.php
Select location
$query = mysql_query("select * from city");
while($row = mysql_fetch_assoc($query))
{
echo ''.$row['cityname']. '';
}
?>
Jquery脚本
function getState(city_id)
{
var html = $.ajax({
type: "POST",
url: "path/to/ajax/my_ajax.php",
data: "city_id=" +city_id,
async: false
}).responseText;
if(html){
$("#state").html(html);
}
}
AJAX.php
$query = mysql_query("select * from state where city_id=".$_REQUEST['city_id']);
while($row = mysql_fetch_assoc($query))
{
echo ''.$row['state_name']. '';
}