asp中关于ajax查询显示多个值的问题,懂的朋友进啊!!急,在线等,立刻结贴!

softffly 2008-07-19 01:31:52
要实现功能是在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

%>



...全文
326 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
softffly 2008-07-19
  • 打赏
  • 举报
回复
好了,谢谢
sy_binbin 2008-07-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 softffly 的回复:]
strArr数组有值,但strArr(1);赋值给不了啊??是不是引用错误
[/Quote]


把你res 里的数据贴出来
softffly 2008-07-19
  • 打赏
  • 举报
回复
strArr数组有值,但strArr(1);赋值给不了啊??是不是引用错误
softffly 2008-07-19
  • 打赏
  • 举报
回复
恩,我先试试,谢谢朋友了
sy_binbin 2008-07-19
  • 打赏
  • 举报
回复
首先你要先在xmlhttp.asp这个文件里把你要输出的字段都给查出来,然后链接成一个字符串
response.write rs("product_id")&","&rs("product_name")&","&规格&","&形状




然后
function getName(product)
{
var id;
id = document.getElementById("myid").value;
xmlhttp.open("get","xmlhttp.asp?id="+id);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4){
var res = unescape(xmlhttp.responseText);//接收服务器返回的数据
var strArr = new Array();
strArr=res.split(',');
document.getElementById("myname").value =strArr(1);
document.getElementById("size").value =strArr(2);


}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}


你这样先试试
softffly 2008-07-19
  • 打赏
  • 举报
回复
朋友走了??????????谁能帮我?



地址给你,朋友看下http://cn.daoq.com/showmotif.asp
现在只能通过 document.getElementById("myname").value =unescape(xmlhttp.responseText);
返回到一个文本框中,其它的不能传值啊
softffly 2008-07-19
  • 打赏
  • 举报
回复
地址给你,朋友看下http://cn.daoq.com/showmotif.asp
现在只能通过 document.getElementById("myname").value =unescape(xmlhttp.responseText);
返回到一个文本框中,其它的不能传值啊
softffly 2008-07-19
  • 打赏
  • 举报
回复
是的
sy_binbin 2008-07-19
  • 打赏
  • 举报
回复
一个产品有多个形状????
softffly 2008-07-19
  • 打赏
  • 举报
回复
不是的,这样的我也不要问朋友了,是规格要放到规格的文本框中,形状 (多个)要放到下拉列表中.
有点难度的!!需要调用xmlhttp.asp中的变量。(定义产品id,产品名称,产品规格的变量,并且回传各个变量多对于的文本框或下拉框中)
sy_binbin 2008-07-19
  • 打赏
  • 举报
回复
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")&","&rs("product_name")&","&规格&","&形状
else
response.Write "暂无信息"
end if

%>


然后在motif.asp里先
var res = xml.responseText;//接收服务器返回的数据

var strArr = new Array();
strArr=res.split(',');


myname=document.getElementById("myname");
myname.innerText=strArr[1];

size=document.getElementById("size");
size.innerText=strArr[2];


大概就这个意思吧

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧