[求助]ajax实例的一个问题
<P>请问这种情况怎么处理啊<BR>在getInfo()使用responseText中反馈回查询数据.<BR>在下面使用<BR>function check() <BR>{getInfo();<BR>var alltxt=allcontent;<BR>......<BR>}<BR>但是check中只能使用上一次getInfo()查询出来的数据<BR>应该怎么处理才能使用本次onkeyup触发后反馈的查询数据啊<BR><BR>原码如下:<BR><%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="http://www.w3.org/TR/html4/loose.dtd" target="_blank" >http://www.w3.org/TR/html4/loose.dtd</A>"><BR><html><BR><head><BR><link href="./images/css/body.css" rel="stylesheet" type="text/css"><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR><title>病虫害查询</title><BR><script language="javascript" ><BR>var httprequest;<BR>var allcontent;<BR>function createRequest()<BR>{<BR> try{<BR> httprequest=new XMLHttpRequest();<BR> }catch(trymicrosoft)<BR> {<BR> try{<BR> httprequest=new ActiveXObject("Msxml2.XMLHTTP");<BR> }catch(othermicrosoft)<BR> {<BR> try{<BR> httprequest=new ActiveXObject("Microsoft.XMLHTTP");<BR> }<BR> catch(failed)<BR> {<BR> httprequest=false;<BR> }<BR> }<BR> }<BR> if(!httprequest)<BR> {<BR> alert("err Happend!");<BR> return null;<BR> } <BR> return httprequest;<BR>}<BR>function getInfo()<BR>{ createRequest();<BR> var username=document.getElementById("name").value;<BR> if(username!="")<BR> {var url='answer.jsp?name='+username;<BR> httprequest.open("GET",url,"true");<BR> httprequest.onreadystatechange=disResult;//隐性的循环<BR> httprequest.send(null);<BR> }<BR>}<BR>function disResult()<BR>{<BR> if(httprequest.readystate==4)<BR> {<BR> if(httprequest.status==200)<BR> {<BR> allcontent = httprequest.responseText;<BR> }<BR> else<BR> {<BR> alert('Something Wrong has Happend!'+httprequest.status);<BR> }<BR> }<BR>return allcontent; <BR>}<BR>function wait()<BR>{}<BR>function checkword()<BR>{<BR>allcontent="ssd";<BR>getInfo();<BR>var wordvalue=document.getElementById("name").value.toLowerCase();<BR>var alltxt=allcontent;<BR>var alltxtpp=alltxt.toLowerCase();<BR>var alltxt_xiang=alltxt.split("|");<BR>var alltxt_xiang1=alltxtpp.split("|");<BR>var inhtml="<ul>"<BR>var isyou=0;<BR>for (i=0;i<alltxt_xiang1.length;i++)<BR>{<BR>if(alltxt_xiang1[i].substr(0,1)!="")<BR>{<BR>inhtml=inhtml+"<li onclick=\"document.getElementById('name').value=this.innerHTML;document.getElementById('showmenu').style.display='none';\" onmouseover=\"this.style.backgroundColor='#666666'\" onmouseout=\"this.style.backgroundColor=''\">"+alltxt_xiang[i]+"</li>";<BR>isyou=1;}<BR>}<BR>inhtml=inhtml+"</ul>";<BR>if (isyou==1)<BR>{<BR>document.getElementById("showmenu").innerHTML=inhtml;<BR>document.getElementById("showmenu").style.display="";<BR>}<BR>else<BR>{<BR>document.getElementById("showmenu").innerHTML="";<BR>document.getElementById("showmenu").style.display="none";<BR>}<BR>if (wordvalue=="")<BR>{<BR>document.getElementById("showmenu").innerHTML="";<BR>document.getElementById("showmenu").style.display="none";<BR>}<BR>}<BR></script><BR></head><BR><body><BR><form name="chaxun" method="post" action=""><BR><input name="label" type="button" value="虫害名称"></input><BR><input name="name" type="text" style="" id="name" onkeyup="checkword();" onblur="checkword();" autocomplete = "off" value=""></input><BR><div style="position: absolute; width: 200px; height: 100px; z-index: 1; left: 10px; top: 40px;border:1px solid #666666;display:none; font-size:14px" id="showmenu"></div><BR><input type="submit" value="提交" style=""></input><BR><input type="reset" value="取消" style=""></input><BR><input name="name" type="button" value="帮助"></input><BR><form name="chaxun" method="post" action=""><BR><br><BR><input name="d" type="button" value="病害名称"></input><BR><input name="df" type="text" style=""></input><BR><input type="submit" value="提交" style=""></input><BR><input type="reset" value="取消" style=""></input><BR></form><BR></body><BR></html><BR><BR>请求页answer.jsp执行数据库查询并按照 "士大夫的|你好|不|" 的格式返回数据.<BR><BR>遇到问题<BR>例如:输入 "你" 第一次未定义的allcontent,<BR>再输入 "褐" 会反馈回第一个字"你"查询出来的结果,<BR>同理 再输入 "病"反馈回第二个字"褐"查询出来的结果,<BR>如果重复输入,反馈没有问题,估计是从IE temp文件中读取的内容.<BR><BR></P>页:
[1]
