fishbottle 发表于 2013-2-7 20:39:20

XmlHttpRequest实例

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>xmlhttprequest demo</title><script type="text/javascript" language="javascript">var xmlHttp;function createXmlHttpRequestObject(url){try{    xmlHttp = new XMLHttpRequest();}catch(e){    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",                        "MSXML2.XMLHTTP.5.0",                        "MSXML2.XMLHTTP.4.0",                        "MSXML2.XMLHTTP.3.0",                        "MSXML2.XMLHTTP",                        "Microsoft.XMLHTTP");                              for(var i=0;i<XmlHttpVersions.length && !xmlHttp; i++)    {      try      {      xmlHttp = new ActiveXObject(XmlHttpVersions);      }      catch(e){}    }}    if(!xmlHttp)    alert('Error creating the XMLHttpRequest object.');else{    xmlHttp.open("GET",url,true);    xmlHttp.onreadystatechange = callback;    xmlHttp.send(null);}}function callback(){if(xmlHttp.readystate == 4) //successful{    if(xmlHttp.status==200) //OK    {      Display();    }    else    {      alert("error!");    }}else{    document.getElementById("myTime").innerHTML="loading..." + new Date();}}function Display(){document.getElementById("myTime").innerHTML=xmlHttp.responseText;}</script></head><body><div id="myTime"></div><input id="Button1" type="button" value="获取内容" /></body></html> 
 
参考:http://www.cnblogs.com/chy710/archive/2007/04/15/713868.html 
页: [1]
查看完整版本: XmlHttpRequest实例