<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://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>
以上就是xmlhttp异步获取网站数据的代码案例分析的详细内容。
