在静态页面如何实现js加载内容?
下面是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>