| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1381 人关注过本帖
标题:[求助]ajax实例的一个问题
只看楼主 加入收藏
huangwanfu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-19
收藏
 问题点数:0 回复次数:0 
[求助]ajax实例的一个问题

请问这种情况怎么处理啊
在getInfo()使用responseText中反馈回查询数据.
在下面使用
function check()
{getInfo();
var alltxt=allcontent;
......
}
但是check中只能使用上一次getInfo()查询出来的数据
应该怎么处理才能使用本次onkeyup触发后反馈的查询数据啊

原码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="./images/css/body.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>病虫害查询</title>
<script language="javascript" >
var httprequest;
var allcontent;
function createRequest()
{
try{
httprequest=new XMLHttpRequest();
}catch(trymicrosoft)
{
try{
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
}catch(othermicrosoft)
{
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(failed)
{
httprequest=false;
}
}
}
if(!httprequest)
{
alert("err Happend!");
return null;
}
return httprequest;
}
function getInfo()
{ createRequest();
var username=document.getElementById("name").value;
if(username!="")
{var url='answer.jsp?name='+username;
httprequest.open("GET",url,"true");
httprequest.onreadystatechange=disResult;//隐性的循环
httprequest.send(null);
}
}
function disResult()
{
if(httprequest.readystate==4)
{
if(httprequest.status==200)
{
allcontent = httprequest.responseText;
}
else
{
alert('Something Wrong has Happend!'+httprequest.status);
}
}
return allcontent;
}
function wait()
{}
function checkword()
{
allcontent="ssd";
getInfo();
var wordvalue=document.getElementById("name").value.toLowerCase();
var alltxt=allcontent;
var alltxtpp=alltxt.toLowerCase();
var alltxt_xiang=alltxt.split("|");
var alltxt_xiang1=alltxtpp.split("|");
var inhtml="<ul>"
var isyou=0;
for (i=0;i<alltxt_xiang1.length;i++)
{
if(alltxt_xiang1[i].substr(0,1)!="")
{
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>";
isyou=1;}
}
inhtml=inhtml+"</ul>";
if (isyou==1)
{
document.getElementById("showmenu").innerHTML=inhtml;
document.getElementById("showmenu").style.display="";
}
else
{
document.getElementById("showmenu").innerHTML="";
document.getElementById("showmenu").style.display="none";
}
if (wordvalue=="")
{
document.getElementById("showmenu").innerHTML="";
document.getElementById("showmenu").style.display="none";
}
}
</script>
</head>
<body>
<form name="chaxun" method="post" action="">
<input name="label" type="button" value="虫害名称"></input>
<input name="name" type="text" style="" id="name" onkeyup="checkword();" onblur="checkword();" autocomplete = "off" value=""></input>
<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>
<input type="submit" value="提交" style=""></input>
<input type="reset" value="取消" style=""></input>
<input name="name" type="button" value="帮助"></input>
<form name="chaxun" method="post" action="">
<br>
<input name="d" type="button" value="病害名称"></input>
<input name="df" type="text" style=""></input>
<input type="submit" value="提交" style=""></input>
<input type="reset" value="取消" style=""></input>
</form>
</body>
</html>

请求页answer.jsp执行数据库查询并按照 "士大夫的|你好|不|" 的格式返回数据.

遇到问题
例如:输入 "你" 第一次未定义的allcontent,
再输入 "褐" 会反馈回第一个字"你"查询出来的结果,
同理 再输入 "病"反馈回第二个字"褐"查询出来的结果,
如果重复输入,反馈没有问题,估计是从IE temp文件中读取的内容.

搜索更多相关主题的帖子: ajax 实例 java getInfo 
2007-09-19 16:24
快速回复:[求助]ajax实例的一个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019683 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved