62,046
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>Ajax Sample</title>
<script type="text/javascript">
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
function makerequest(serverPage,objId)
{
var obj = document.getElementById(objId);
xmlHttp.open("GET", serverPage);
xmlHttp.onreadystatechange = function()
{
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
obj.innerHTML = xmlHttp.responseText;
}
}
xmlHttp.send(null);
}
</script>
<body onLoad="makerequest ('content1.html','hw')">
<div align="center">
<h1>My Webpage</h1>
<a href="content1.html" onClick="makerequest('content1.html','hw'); return false;">Page 1</a>
<a href="content2.html" onClick="makerequest('content2.html','hw'); return false;">Page 2</a>
<a href="content3.html" onClick="makerequest('content3.html','hw'); return false;">Page 3</a>
<a href="content4.html" onClick="makerequest('content4.html','hw'); return false;">Page 4</a>
//这里就是将要替换content1~4.html的位置。
<div id="hw"></div>
</div>
</body>
</html>