Ajax主要请求代码:
function showHint()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Ajax not support");
return;
}
var url="syncsendtocp";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
通过window.setInterval('showHint()', 6000);进行定时执行
SyncSendToCP HttpServlet响应代码
public void doGet(HttpServletRequest req, HttpServletResponse resp){
try{
PrintWriter pw=resp.getWriter();
pw.println(change);
pw.flush();
pw.close();
}catch(Exception e){
e.printStackTrace();
}
}
web配置文件
SyncSendToCP
com.openlab.publicopinion.struts.action.SyncSendToCP
debug
0
1
遇到的问题是这样,第一次Ajax执行到后台查询数据的时候,SyncSendToCP的DoGet方法能正常响应,但是Ajax循环执行到第二次以及以后的时候,SyncSendToCP的DoGet方法根本没有响应,感觉像是没有获取到这个Get请求,是为什么呀?