Code case analysis of XmlHttp asynchronously obtaining website data

黄舟
Release: 2017-03-27 16:59:11
Original
1530 people have browsed it

XmlHttp asynchronously obtains website data code case analysis

<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>
Copy after login

xmlhttp asynchronous example:

URL:<input name=a value="http://bianceng.cn" 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>
Copy after login

The above is the detailed content of Code case analysis of XmlHttp asynchronously obtaining website data. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!