写了一个小型网页想练习一下ajax,代码如下,在本地服务器调试,返回的JSON数据总是FALSE,状态值是4,状态码是0,估计可能被服务器拒绝访问了?请各位指教哪儿有问题
<!doctype html>
<html>
<head>
<title>测试</title>
<link rel="stylesheet" href="style/user.css">
</head>
<body>
<!-- <form action="" method="post" onsubmit="SendRequest();return false">-->
<table>
<tr>
<td>
请输入用户姓名:<input type="text" id="username">
</td>
<td>
<input type="button" id="submit" value="提交" onclick="SendRequest()">
</td>
</tr>
<tr>
<td id="test">测试</td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
var xmlhttp;
function SendRequest() {
var username = document.getElementById("username").value;
var td = document.getElementById("test");
if (username != "") {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp) {
var para = "intent=REFRESH"+“username=lzllzllzl”;
var url = "http://localhost:8080/BXTest_3/server?intent=REFRESH&username=lzllzllzl";
xmlhttp.open("get", url, true);
// xmlhttp.setRequestHeader('Content-Type', 'applocation/x-www-from-urlencoded')
xmlhttp.send(para);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4&&xmlhttp.status==0 ) {
var result = xmlhttp.responseText;
// var users = eval(result);
if(xmlhttp.responseText==false) alert("666");
// if(xmlhttp.status<200)
// {
// tr.innerHTML=xmlhttp.status;
// }
// if(xmlhttp.status>=200)
// {
// tr.innerHTML=">200";
// }
// if(xmlhttp.status>=300)
// {
// tr.innerHTML=">300";
// }
// if(xmlhttp.status>=400)
// {
// tr.innerHTML="400";
// }
// if(xmlhttp.status>=500)
// {
// tr.innerHTML="50";
// }
}
}
}
}
}
</script>
</html>