六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 125|回复: 0

XmlHttpRequest实例

[复制链接]

升级  72%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
36
 楼主| 发表于 2013-2-7 20:39:20 | 显示全部楼层 |阅读模式
<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 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表