2012-04-27 76 views
0

我有这样的代码的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> 

但是当我点击按钮,没有任何happends和Chrome开发人员工具说,“一个”没有定义。我该怎么办?

+0

你应该知道如何正确地格式化代码后,问了33个问题。 – 2012-04-27 18:56:24

+0

感谢您重新格式化我。 – 2012-04-27 18:57:55

+0

我发现使用'onclick'属性而不是史前:P – Kerstomaat 2012-04-27 18:59:13

回答

1

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

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

因此a是不确定的。

+0

哎呀,我确实看到它,但它不知何故跳回来。谢谢。 – 2012-04-27 18:58:31

+0

也在这里:'xmlhttp.open(“POST”,“new”,false);' – 2012-04-27 19:01:06

+0

哦,天哪,你是对的。谢谢! – 2012-04-27 19:02:28

1

删除后的时间段: xmlhttp.open(“POST”,“write”,false);. xmlhttp.open(“POST”,“new”,false);.

相关问题