<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<script type="text/javascript" src="js/AjaxRequest.js" language="javascript"></script>
<script type="text/javascript">
function getFullTime(){
var loader = net.AjaxRequest("showTime.jsp?nocache="+new Date().getTime(),deal_t,onerror,"GET");
}
function deal_t(){
document.getElementById("clock").innerHTML= this.req.responseText;
}
function onerror(){
alert("出错了!");
}
timer = window.setInterval("getFullTime()",1000);
</script>
</head>
<body onload="getFullTime()">
<b>现在的时间是:</b>
<div id="clock">a</div>
</body>
</html>
试过很多方法,包括用window.onload等。showTime.jsp页面可以正常输出时间字符串。AjaxRequest.js在其他的项目里使用也完全正常。只有这里有问题了。。
------解决方案--------------------
在getFullTime中alert一下不就知道有没有执行了,就这么几行代码,慢慢调试呗。
------解决方案--------------------
我试了下是执行的,
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<script type="text/javascript" src="js/AjaxRequest.js" language="javascript"></script>
<script type="text/javascript">
var i=1;
function getFullTime(){
document.getElementById("clock").innerHTML=""+(i++);
//var loader = net.AjaxRequest("showTime.jsp?nocache="+new Date().getTime(),deal_t,onerror,"GET");
}
function deal_t(){
document.getElementById("clock").innerHTML= this.req.responseText;
}
function onerror(){
alert("出错了!");
}
timer = window.setInterval("getFullTime()",1000);
</script>
</head>
<body onload="getFullTime()">
<b>现在的时间是:</b>
<div id="clock">a</div>
</body>
</html>
这个方法中的
function getFullTime(){
var loader = net.AjaxRequest("showTime.jsp?nocache="+new Date().getTime(),deal_t,onerror,"GET");
}
var loader = net.AjaxRequest("showTime.jsp?nocache="+new Date().getTime(),deal_t,onerror,"GET");
这句如果没有错的话,应该把执行结果赋值给clock
------解决方案--------------------
火狐的firebug