XmlHttp异步获取网站数据的例子
1
<script>
2
var oDiv
3
var xh
4
function getXML()
5
{
6
oDiv = document.all.m
7
oDiv.innerHTML = "正在装载栏目数据,请稍侯
."
8
oDiv.style.display= ""
9
xh = new ActiveXObject("Microsoft.XMLHTTP")
10
xh.onreadystatechange = getReady
11
xh.open("GET",a.value,true)
12
xh.send()
13
oDiv.innerHTML=xh.responseText;
14
}
15
16
function getReady()
17
{
18
if(xh.readyState==4)
19
{
20
if(xh.status==200)
21
{
22
23
oDiv.innerHTML = "完成"
24
}
25
else
26
{
27
oDiv.innerHTML = "抱歉,装载数据失败。原因:" + xh.statusText
28
}
29
}
30
}
31
</script>
32
<body>
33
xmlhttp异步的例子:
34
URL:<input name=a value="http://ewebapp.cnblogs.com/Rss.aspx" style="width:600px">
35
<input onclick="getXML()" type="button" value="得到源代码">
36
37
<script>2
var oDiv 3
var xh 4
function getXML()5
{6
oDiv = document.all.m7
oDiv.innerHTML = "正在装载栏目数据,请稍侯
."8
oDiv.style.display= ""9
xh = new ActiveXObject("Microsoft.XMLHTTP")10
xh.onreadystatechange = getReady11
xh.open("GET",a.value,true)12
xh.send()13
oDiv.innerHTML=xh.responseText;14
}15

16
function getReady()17
{18
if(xh.readyState==4)19
{20
if(xh.status==200)21
{22

23
oDiv.innerHTML = "完成"24
}25
else26
{27
oDiv.innerHTML = "抱歉,装载数据失败。原因:" + xh.statusText28
}29
}30
}31
</script>32
<body>33
xmlhttp异步的例子:34
URL:<input name=a value="http://ewebapp.cnblogs.com/Rss.aspx" style="width:600px">35
<input onclick="getXML()" type="button" value="得到源代码">36

37


浙公网安备 33010602011771号