我有这个代码
<title>Welcome</title>
<head>
<script type="text/javascript">
var id = "...";
var sessionCount = 0;
var sessionText=[];
var dumper=[];
function a()
{
var i = 0;
var processor = setInterval("refresh()", 500);
}
function refresh()
{
sessioncount();
readsessions();
htmlize();
newsession();
send("some awesome test");
}
function sessioncount()
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","count", false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("id="+id);
sessionCount = parseInt(xmlhttp.responseText);
}
function readsessions()
{
sessionText = new Array(sessionCount);
for(var i = 0; i < sessionCount; i++)
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","read?i="+i, false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("id="+id);
sessionText[i] = xmlhttp.ResponseText;
}
}
function newsession()
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","new", false);.
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("id="+id);
}
function send(msg)
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","write", false);.
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("msg="+msg+"&id="+id);
}
function htmlize()
{
while(sessionCount > dumper.Length)
dumper.push("");
for(var i = 0; i < sessoinCount; i++)
{
dumper[i] += sessionText[i];
alert(dumper[i]);
}
}
</script>
</head>
<body bgcolor="black">
<font color="white">
<FORM>
<INPUT TYPE="button" VALUE="GO" onclick="a()">
</FORM>
但是当我点击按钮时,什么也没有发生,Chrome 开发者工具说“a”没有定义。我该怎么办?