singleselect.html静态下拉菜单使用AJAX,PHP
<html>
<script>
function singleselect(str)
{
var xmlhttp;
if(str.length == 0)
{
document.getElementById("sing").innerHTML="";
return;
}
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhtttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4)
{
document.getElementById("sing").innerHTML = xmlhttp.responsetext;
}
}
xmlhttp.open("POST","singleselect.php?s=" +str,true);
xmlhttp.send();
}
</script>
<style>
div { font-family:verdana; font-size:13px; margin-left:400px; margin-top:100px; }
</style>
<body>
<div>
Select a country :
<select onchange="document(this.value)">
<option>Select a country</option>
<option value="0">INDIA</option>
<option value="1">United States of America</option>
<option value="2">United Kingdom</option>
<option value="3">Australia</option>
</select>
</div>
<div id="sing"></div>
</body>
</html>
singleselect.php
<?php
$store[0] = "Please select a country";
$store[1] = "Andhra Pradesh";
$store[2] = "New York";
$store[3] = "London";
$store[4] = "Austraila";
$s = $_REQUEST['s'];
?>
当我点击一个国家,应该显示关系到一个国家的状态列表,我想在PHP中使用静态数据库来完成。因为我是jQuery和AJAX。我需要你的指导。
你是什么意思静态?如果您从selectbox传送值,则需要
但我想使用静态内容而不是从数据库中使用 – ronbosc 2013-03-07 07:52:10
您写道“我想在PHP中使用静态数据库来完成,但使用数据库”,所以你让我感到困惑。那么你将不得不在文本文件或CSV或任何其他国家的这个国家的名单,并以这种方式格式化,以便您可以轻松阅读。例如,如果你使用文本文件,也许你可以像这样格式化国家:城市;然后读取文件explode(),以便获取数组并搜索所需的值。搜索网络阅读txt文件和爆炸()函数 – vodich 2013-03-07 07:57:21