专注于网站技术与网络营销的博客

赞助商链接

« vbscript中用正则时获得匹配串的心得showModalDialog()、showModelessDialog()方法使用详解 »

XmlHttp异步获取网站数据的例子



<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
  }
 }
}
</script>
<body>
xmlhttp异步的例子:
URL:<input name=a value="http://www.microsoft.com" style="width:600px">
<input onclick="getXML()" type="button" value="得到源代码">
<input onclick="if(xh && xh.responseText) {alert(xh.responseText);oDiv.innerHTML=xh.responseText}" type="button" value="显示源代码">
<div id=m></div>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80710

Copyright 2005 - 2008, 完美生活(专注于网站技术与网络营销的博客). Some Rights Reserved.