ajax 最简单的问题
这是jsp页面
<script language= "javascript ">
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject( "Msxml2.XMLHTTP ");
} catch (othermicrosoft) {
try {
request = new ActiveXObject( "Microsoft.XMLHTTP ");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert( "加载ajax失败! ");
function richeng(){
var path= " <%=request.getContextPath()%> ";
var url = path+ "/getRicheng.do ";
request.open( "GET ", url, true);
request.send(null);
if (request.readyState == 4)//即 HTTP 就绪状态是 4
if (request.status == 200)//状态码是 200,它表示一切顺利
{
if(request.responseText!= " "){
alert(request.responseText);//服务器返回数据
}
}
else if (request.status == 404)
alert( "Request URL does not exist ");
else
alert( "Error: status code is " + request.status)
}
setInterval( "richeng() ",10000);
</script>
<body onload= "richeng(); ">
</body>
用意是每隔10秒就向服务器请求一次查询,就是getRicheng.do
getRichengActino如下:
AlarmManager mgr = new AlarmManager();
HttpSession sess = request.getSession(true);
Calendar c = Calendar.getInstance();
boolean flag=true;
String queue= " ";
final PrintWriter out=response.getWriter();
CalendarTaskDAOImpl ctdao=new CalendarTaskDAOImpl();
List lists=ctdao.getTasks(sess.getAttribute( "userID "));
System.out.println( "ajax ");
for(Iterator it=lists.iterator();it.hasNext();){
CyoaCalendarDetail taska = (CyoaCalendarDetail)it.next();
final String memo=taska.getMemo();
String importrace=taska.getImportace();