asp中关于ajax查询显示多个值的问题,懂的朋友进啊!!急,在线等,立刻结贴!
要实现功能是在motif.asp中输入产品id则自动在一下文本框中显示名称,规格,形状(产品形状很多,所以是列表框全部列出)。现在的代码是motif.asp只能赋值到一个文本框中,其它的不能赋值,因为赋值是通过xmlhttp.responseText从xmlhttp.asp中传递过来的。怎么可以做到多个相应的值传递过来,就是说怎么传递xmlhttp.asp中的变量值呢??
页面motif.asp:代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
<!--
var xmlhttp;
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
function getName()
{
var id;
id = document.getElementById("myid").value;
xmlhttp.open("get","xmlhttp.asp?id="+id);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4){
document.getElementById("myname").value =unescape(xmlhttp.responseText);
}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}
//-->
</script>
<title>实现即时查找数据 </title>
</head>
<body>
Name: <input type="text" id="myname" name="myname" />
size
<input name="size" type="text" id="size" />
shape
<select name="shape" id="shape">
</select>
</body>
</html>
xmlhttp.asp代码如下:
<%
Response.charset="GB2312"
on error resume next
set conn=server.CreateObject("adodb.connection")
strconn="Driver={SQL SERVER};Server=.;uid=sa;pwd=sa;database=memay;"
conn.open strconn
If Err Then
err.Clear
Set conn = Nothing
Response.Write Err.Description
Response.End
End If
set rs = server.CreateObject ("adodb.recordset")
id=Request.QueryString("id")
sql="select * from product where id="&id
rs.open sql,conn,1,1
if not rs.bof then
response.Write rs("product_id")
product_name=rs("product_name")
else
response.Write "暂无信息"
end if
%>