XMLHTTP异步的例子

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> XMLHTTP异步的例子 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
body,p,tr,td,div,input {font-size:9pt}
</style>
<script>
var oDiv;
var xh;
function getXML()
{
 oDiv = document.all.m;
 oDiv.innerHTML = "正在装载栏目数据,请稍侯.......";
 oDiv.style.display= "";
 xh = new ActiveXObject("Microsoft.XMLHTTP");
 xh.onreadystatechange = getReady;
 xh.open("GET",a.value,true);
 xh.send();
}

function getReady()
{
 if(xh.readyState==4)
 {
  if(xh.status==200)
  {
   oDiv.innerHTML = "完成";
  }
  else
  {
   oDiv.innerHTML = "抱歉,装载数据失败。原因:" + xh.statusText;
  }
 }
}

function showCode(p)
{
 if(xh && xh.responseText)
 {
  if(p>0)
   oDiv.innerHTML=xh.responseText;
  else
  {
   oDiv.innerHTML="<textarea id='coder' name='coder' rows='20' cols='100'></textarea>";
   coder.value=xh.responseText;
  }
 }
}
</script>
</head>
<body>
<h4>xmlhttp异步的例子</h4>
URL:<input name=a value="http://cn.php.net" size="40">
<input οnclick="getXML()" type="button" value="获取源代码">
<input οnclick="showCode(0)" type="button" value="显示HTML源代码">
<input οnclick="showCode(1)" type="button" value="显示WEB页面">
<hr>
<div id=m></div>
</body>
</html>

原文地址:https://www.cnblogs.com/longware/p/13382468.html