下面是Html代碼,復制就行了
AJax加載頁面文檔
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
XMLns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=utf-8" />
<meta name="Cache-Control"
content="no-cache"/>
<title>AJax加載頁面文檔</title>
</head>
<body>
<script type="text/Javascript">
var request=null;
//以下創
建請求對象並發送
function requestHttpObj(url,func){
if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
request=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
request=new ActiveXObject
("Microsoft.XMLHTTP")
}catch(e){
request=false;
}
}
};
if(request){
request.onreadystatechange=func;
request.open("GET",url,true);
request.send(null);
}
}
//以上創建請求對象並發送
//以下定義請求回應函數
function succesRequest(){
if(request.readyState==4){
var str=request.responseText;
document.write(str);
}
}
//以上定義請求
回應函數
//以下構造地址,後面加即時時間字符串是為了清每次請求的緩存
//請求哪個頁面更改下面這個變量裡網頁地址的值即可;
//在本地保存此頁用IE浏覽器可以請求任意網址的網頁
,最好是utf-8編碼,
現在這個地址的頁面是gbk編碼的,顯示出來會有亂碼;
//要發布到網上的話,地址只能是與此頁面同域的頁面,說簡單點就是域名差不多啦
//如果在同一台服務器
下可以用相對路徑來表示
var url="http://bbs.blueidea.com/index.PHP?time="+new Date().valueOf();
window.onload=requestHttpObj(url,succesRequest)
</script>
</body>
</Html>