且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ajax:显示url网页内容的通用函数

更新时间:2022-06-05 08:23:50

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Ajax</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
/**
* 显示url网页内容的通用函数
* Program: 54powerman
* EMail: 54powerman@163.com
* HomePage: http://blog.163.com/54powerman
* Parameters:
* url——要获取内容的网页
* obj——显示内容的容器对象,如:DIV
**/
function getContent(url,obj)
{
 this.forObject=obj;

 this.forObject.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 this.forObject.xmlhttp.open("POST",url,true);
 this.forObject.xmlhttp.onreadystatechange=function(){
  if(this.forObject.xmlhttp.readyState==4){
   if(this.forObject.xmlhttp.status==200){
    this.forObject.innerHTML=this.forObject.xmlhttp.responseText;
   }
   else
   {
    this.forObject.innerHTML="<font color=red>数据源错误。</font>";
   }
  }
 };
 obj.xmlhttp.send();
}

function demo()
{
 var obj=document.getElementById("abc");
 var str=getContent("http://iask.sina.com.cn/b/6528570.html",obj);
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<INPUT TYPE="button" value="显示文件内容" >
<div >