0

我有这个代码

<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”没有定义。我该怎么办?

4

2 回答 2

1

你在这里有一个语法错误:

xmlhttp.open("POST","write", false);. // <-- that dot should not be there

因此a是未定义的。

于 2012-04-27T18:57:59.973 回答
1

删除之后的句点:xmlhttp.open("POST","write", false);。xmlhttp.open("POST","new", false);.

于 2012-04-27T19:00:12.390 回答