Javascript按钮OnClick无法找到我想要的方法

时间:2012-04-27 18:55:20

标签: javascript onclick

我有这段代码

<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 Developer工具说没有定义“a”。我该怎么办?

2 个答案:

答案 0 :(得分:1)

这里有语法错误:

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

因此a未定义。

答案 1 :(得分:1)

删除以下时段后: xmlhttp.open(“POST”,“write”,false);. xmlhttp.open(“POST”,“new”,false);。