<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.ddvip.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>