读书人

新手有关问题~请各位帮忙

发布时间: 2012-03-28 15:40:03 作者: rapoo

新手问题~~~~~请各位帮忙 - Web 开发 / Ajax
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> </title>
<script language="javascript">

var xmlhttp;

function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}

function startRequest()
{
createXMLHttpRequest();
xmlhttp.onreadystatechange = handleStateChange;
xmlhttp.open("GET","simpleRequest.xml",true);
xmlhttp.send(null);
}

function handleStateChange()
{
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
document.getElementById("results").innerHTML = xmlhttp.responseText;
}
}
}

</script>
</head>

<body>

<form action="#">

<input type="button" value="afasfasfasf" onclick="startRequest();" />

</form>

<div id="results"> </div>

</body>
</html>

simpleRequest.xml文件中的内容是如下:
<table border="1">
<tbody>
<tr>
<th>time </th>
<th>location </th>
<th>name </th>
<th>birthday </th>
</tr>
<tr>
<th>12313 </th>
<th>asfasf </th>
<th>wolf </th>
<th>87698789 </th>
</tr>
</tbody>
</table>

为什么就是调试不出来呢,没有任何显示或者报错~~~~ 我是初学ajax,是需要什么配置还是什么啊??

[解决办法]
ajax不需要配置什么.
[解决办法]

JScript code
function handleStateChange()  {  if(xmlhttp.readyState == 4)  {  if(xmlhttp.status == 200||xmlhttp.status == 0)//xmlhttp.status==0 加上,如果你是直接拖进浏览器的话{  document.getElementById("results").innerHTML = xmlhttp.responseText;  }  }  }
[解决办法]
我也是刚刚接触,需要学习呀.

读书人网 >Ajax

热点推荐