TEST
<script type="text/javascript">
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}else{
xmlHttp=new ActiveXObject("Miscrosoft.XMLHTTP");
}
function ChangeContent()
{
xmlHttp.onreadystatechange=StateChange;
xmlHttp.open("Get","test.txt",true);
xmlHttp.send();
}
function StateChange()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
document.getElementById("divTest").innerHTML=xmlHttp.responseText;
}
}
</script>
<body> <div id="divTest"> change the content </div> <button id="btnGet" type="button" onclick="ChangeContent();"> CLICK</button> </body> </html>
本文介绍了一种利用Ajax技术动态加载网页内容的方法。通过JavaScript实现GET请求从服务器获取文本文件,并将返回的内容插入到指定的HTML元素中,从而实现局部页面更新而无需刷新整个页面。
2537

被折叠的 条评论
为什么被折叠?



