日期:2014-05-16  浏览次数:20612 次

急急急,菜鸟求助关于XMLHTTPRequest的问题
在使用xmlhttprequest时总是不刷新页面,不知道怎么回事,点击按钮总是没反应,求助高手,代码如下,谢谢
<head runat="server">
  <title></title>
  <script type = "text/javascript">
  function commit() {
  var httpobj;
  if (window.XMLHttpRequest) {
  httpobj = new XMLHttpRequest();
  }
  else {
  httpobj = new ActiveXObject("Microsoft.XMLHTTP");
  }
  httpobj.onreadystatechange = function() {
  if (httpobj.readyState == 4 && httpobj.status == 200) {
  document.getElementById("MyDiv").innerHTML = httpobj.responseText;
  }
  }
  httpobj.open("GET", "f02.aspx", true);
  httpobj.send();
  }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <input type = "button" value = "检测用户名" onclick = "return commit()" />
  </div>
  <div id = "MyDiv"></div>
  </form>
</body>

------解决方案--------------------
火狐下可以设断点,你断点试试,看commit()函数执行了吗。
记得修改后要清一下缓存。
------解决方案--------------------
页面代码木有问题,f02.aspx这里面返回的是什么信息?Response.Write();是否这个返回