还是不行,哪位能帮我看看如何解决?
我的程序可以在360浏览器中运行,但是因为有的人是用xp+IE6,所以需要更改下。
我的程序是希望在客户端的输入款uname中输入少许的字符,就通过AJAX获取服务器端
相关的数据记录,并在ListBox中显示,然后在ListBox点击某一行,获取数据。
这里有两个问题:
(1)我在服务器端读取记录的时候,希望一条一条记录返回到客户端的,但是在客户端显示的是选取的全部记录;
请看,这里是用循环语句,每一次返回一条记录(echo $com2),为什么是把所有的记录一次返回,而且
是连在一起的,没有分行?
while($num1)
{
$result_row=$result->fetch_row();
$com2=$result_row[0];
echo $com2;
$num1=$num1-1;
}
(2)应该随时清除ListBox框中的记录,当我在输入款uname中输入少许字符时,在ListBox框中显示相应的记录,而不是
原来的内容没有清除,新的内容又添加进来。请问该怎么办?
请看下面是比较完整的代码:
这个是客户端的程序(主要代码)
<script language="Javascript">
function CListBox() {
var List = document.getElementById("ListBox");
var edit1=document.getElementById("uname");
for (var i = 0; i < List.options.length; i++) {
if (List.options[i].selected == true) {
edit1.value=List.options[i].value;
}
}
}
function DspData()
{
var returnbox = document.getElementById("ListBox");
var nameid = document.getElementById("uname").value;
var xmlhttp;
var url="functionLidSCD.php";
postStr="nameid="+nameid;
xmlhttp =getXmlHttpObject();
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(postStr);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//returnbox.innerHTML =xmlhttp.responseText; //这个在360等浏览器中可以用
//现在要求是在IE6中运行,所以就不能用上面的代码
var tmp=xmlhttp.responseText;
returnbox.options.add(new Option(tmp,tmp));
}
};
}
</SCRIPT>
<form id="form1" name="form1" method="post" action="/fjqsl/sale/inslidSCD.php" >
<p class="STYLE2">盖子名称
<input name="uname" type="text" id="uname" onkeyup="DspData()" />
</p>
<select size="4" name="ListBox" id="ListBox" style="width:300px; height:250px;" onclick="CListBox()">
</select>
服务器程序functionLidSCD.php(主要代码):
<?php
$name = $_POST["nameid"];
$query="select * from lid where name like '%".$name."%'";
$result=$db->query($query);/*执行查询*/
$num1=$result->num_rows; //返回查询的行数
while($num1)
{
$result_row=$result->fetch_row();
$com2=$result_row[0];
//$com1="<option value='".$com2."'>".$com2."</option>"; //如果客户端是360等浏览器,可以用innerHTML,则用这代码
//echo $com1;
echo $com2;
$num1=$num1-1;
}