2007/12/14 | [原创]AJAX入门例子-载入其他网站
类别(AJAX) | 评论(4) | 阅读(830) | 发表于 11:10

-------------代码如下---------------

<HTML>
 <HEAD>
  <TITLE> Ajax测试 </TITLE>
  <META http-equiv=Content-Type content="text/html; charset=utf-8">
  <SCRIPT language=JavaScript type=text/javascript>
 function xh() {
  var a=null;
  try {
   a=new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
   try {
    a=new ActiveXObject("Microsoft.XMLHTTP");
   }catch(oc){
   a=null;
   }
  }
  if ( a && typeof XMLHttpRequest != "undefined" ) {
   a=new XMLHttpRequest();
  }
  return a;
 }
 var xmlHttp = xh();

 function callMe(str_name1) {
  var url1 = str_name1;
  xmlHttp.open("GET", url1, true);
  xmlHttp.onreadystatechange = updatePage11;
  xmlHttp.send(null);
 }
 function updatePage11() {
  if (xmlHttp.readyState == 4) {
   var response = xmlHttp.responseText;
   //Form use "value" e.g. "input" and so on
   //document.getElementById("con1").value = response;
   //Normal html tag use "innerHTML" e.g. "div","table","p","font" and so on
   document.getElementById("con1").innerHTML = response;
  }
 }
  </SCRIPT>
 </HEAD>

 <BODY>
   <TABLE class=clearit style="BACKGROUND: #3fa6b5; WIDTH: 100%"
      cellSpacing=0>
        <TR>
          <TD title=Yahoo onClick="callMe('http://www.yahoo.com')">Yahoo</TD>
          <TD width=1></TD>
          <TD title=Baidu onClick="callMe('http://www.baidu.com')">Baidu</TD>
          <TD width=1></TD>
          <TD title=Sogou onClick="callMe('http://www.sogou.com')">Sogou</TD>
          <TD width=1></TD>
          <TD title=Etoooo onClick="callMe('http://www.etoooo.com')">Etoooo</TD>
          <TD width=10></TD></TR></TBODY></TABLE>
      <DIV class="cont_le picfff" id=con1 style="DISPLAY:block">
  <!--will insert document-->
      </DIV>
   <DIV class=clearit></DIV>
</TABLE>
 </BODY>
</HTML>

24

评论Comments