从网上改的ajax和数据库代码,为什么不能用了???
红色的是我改动的部分,原来是一个下拉框 ,选择其中一项,可无刷新出现相应的表格信息,为什么改后就是乱码??而且想问一下,绿色的q不用定义吗?它的值从哪来啊?我菜鸟一枚。。。。请大神帮帮忙。
<html>
<head>
<script type="text/javascript">
function showCustomer(str)
{
var xmlhttp;
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET"
"getcustomer.asp?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form action="" style="margin-top:15px;">
请选择一位客户:
<ul name="customers" onmouseover="showCustomer(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;">
<li value="APPLE">Apple Computer, Inc.</li>
<li value="BAIDU ">BAIDU, Inc</li>
<li value="Canon">Canon USA, Inc.</li>
<li value="Google">Google, Inc.</li>
<li value="Nokia">Nokia Corporation</li>
<li value="SONY">Sony Corporation of America</li>
</ul>
</form>
<br />
<div id="txtHint">客户信息将在此处列出 ...</div>
</body>
</html>
-----------------------------------------getcustomer.asp-------------------------------------------
<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
rs.Open sql,conn
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td>" & x.value & "</td></tr>")
next
rs.MoveNext
loop
response.write("</table>")
%>
------解决方案--------------------q是跟随在网址后面的参数,接受页面可以通过request读取它