日期:2014-05-16  浏览次数:20948 次

ajax中处理响应的问题
文档一
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function ajaxFunction()

 if(window.ActiveXObject)
  {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if(window.XMLHttpRequest)
  {XMLHttp=new XMLHttpRequest();
  }
  xmlHttp.onreadystatechange=function()
  {
  if(xmlHttp.readyState==4)
  {document.myForm.time.value=xmlHttp.responseText;
  }
  }
  xmlHttp.open("GET","time.jsp",true);
  xmlHttp.send(null);
}
</script>
<form name="myForm">
用户: <input type="text" name="username" onkeyup="ajaxFunction();" />
时间: <input type="text" name="time" />
</form>
</body>
</html>
----------------------------------------------------------------------
文档time.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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" />
<title>无标题文档</title>
<%@ page import="java.util.Date" %>
</head>
<body>
<%
Date time=new Date();
response.expires=-1;
response.write(time);
%>
</body>
</html>

文档一中使用ajax进行异步处理,在用户栏按下键盘时,就会进行异步处理,但是这儿document.myForm.time.value=xmlHttp.responseText
中显示在“时间”中的为什么不是time.jsp中的系统时间,是response.write()用法有误,还是什么??

------解决方案--------------------