//addche.php
<?php
include_once('../func.php');
?>
<html>
<head>
<title>增加文章</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<scrīpt type="text/javascrīpt" src="ajax.js"></scrīpt>
<LINK href="images/mystyle.css" type=text/css rel=StyleSheet>
</head>
<body bgcolor="#FFFFFF" text="#000000" marginwidth="0" marginheight="0">
<br>
<table width="609" border="0" cellspacing="1" cellpadding="1" height="8" bgcolor="#3399CC" align="center">
    <tr> 
      
    <td width="226" height="25"><b><font color="#FFFFFF">&nbsp;车型号管理【大类,小类】</font></b></td>
      <td width="356">&nbsp;</td>
    </tr>
</table>
  <table width="609" border="0" cellspacing="1" cellpadding="4" bgcolor="#99ccff" height="130" align="center">
<form name="FORM" method="post" action="addchexing.php">
    <tr bgcolor="#f2f8ff">
      <td width="57">型 号:</td>
      <td width="533"><select id="state" name="state" ōnChange="getcity()">
<?php
$selectbg = "select * from chexing";
$bgresult = selectfun($selectbg);
 while($myrow = $bgresult->fetch_assoc()){
echo  "<option value=".$myrow['id'].">".$myrow['bgtype']."</option>";
}
?> 
</select> 
<select name="city" id="city">
<option value="">please select state first</option>
</select>      <input type="text" name="textfield3"></td>
    </tr>
    <tr bgcolor="#f2f8ff">
      <td>&nbsp;</td>
      <td><input type="submit" name="addks" value="提交">
      <input type="reset" name="Submit7" value="重置"></td>
    </tr>
</form>
  </table>
</body>
</html>//ajax.js
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                     "MSXML2.XMLHTTP.5.0",
                                     "MSXML2.XMLHTTP.4.0",
                                     "MSXML2.XMLHTTP.3.0",
                                     "MSXML2.XMLHTTP",
                                     "Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
try { 
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);

catch (e) {}
}
}
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else 
return xmlHttp;
}function getcity(){
var selectObj = document.getElementById("state");
var url = "ajax_city.php?stateid=" +escape(selectObj.options[selectObj.selectedIndex].value);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = getcityOk;
xmlHttp.send(null); 
}function getcityOk(){
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
try{
var classObj = document.getElementById("city");
//classObj.innerHTML=response; // 开始的写法,但无论如何也传不到页面中去!→
classObj.outerHTML=response;
}
catch(exception){}

}
//ajax_city.php
<?php 
include('../func.php');
$stateid=$_GET['stateid'];
$citysql = "select * from midchexing where parentid=$stateid";
$city=selectfun($citysql);
echo "<select name=\"city\">"; 
while($myrow = $bgresult->fetch_assoc()){
 echo  "<option value=".$myrow['id'].">".$myrow['midname']."</option>";
}
echo "</select>";
?>
//func.php
<?php
function getconn(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "car";
$conn = new mysqli($servername,$username,$password,$dbname);
if(!$conn){
die("链接数据库出现错误!"); 
}
else
return $conn;
}
function insertfun($sql){
$conn = getconn();
$conn->query("SET character_set_connection=gbk, character_set_results=gbk, character_set_client=binary");
if (!$conn->query($sql)) {
echo die("插入失败!");
}
}
function selectfun($sql){
$conn = getconn();
$conn->query("SET NAMES 'gb2312'");
$result = $conn->query($sql);
if(!$result){
die("不能读出数据");
}else
return $result;
}
function login($username,$pass){
$conn = getconn();
$sql = "select * from user where username='$username' and password='$pass'";
$result = selectfun($sql);
if(!$result){
throw new Exception("登录失败!请您输入正确的用户名和密码!");
}
if ($result->num_rows > 0) {
return true;
}else {
throw new Exception("用户名或密码错误,请重新输入!");
}
}
?>
第一个列表有,但联动不了第二个!各位大虾帮看看!比较急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!超级谢谢了!

解决方案 »

  1.   


    http://topic.csdn.net/u/20080319/10/1163a757-f29c-4555-8def-1acd120c7eb4.html
    这里有附件,看一下是怎么联动的http://topic.csdn.net/u/20080318/21/bc41555c-c834-4f42-9ee0-6835ef8686d7.html
    http://topic.csdn.net/u/20080319/11/b3b7f6dc-3284-4e03-be55-d31f1c268fdc.html
      

  2.   

    你可以把数据读出来放到JS数组里,都用js,这样的例子就多 了,你的这个代码太多了。看的头晕,而且还有个func.php不知道。
      

  3.   


    function getcityOk(){
    if (xmlHttp.readyState == 4) {
    if(xmlHttp.status==200){//是不是少了这个啊。
    var response = xmlHttp.responseText;
    try{
    var classObj = document.getElementById("city");
    //classObj.innerHTML=response; // 开始的写法,但无论如何也传不到页面中去!→
    classObj.outerHTML=response;
    }
    catch(exception){}

    }
    }
      

  4.   

    另外测下PHP返回的数据是否有值,是什么值?是否是合规html
    如果返回值正确,应该显示