示例1:
新建两个文件
test.html
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test1.txt",true);
xmlhttp.send();
}
Let AJAX change this text
通过 AJAX 改变内容
test1.txt
AJAX is not a programming language.It is just a technique for creating better and more interactive web applications.
部署运行
点击“通过AJAX改变内容”
myDiv里的内容就会在页面没刷新的情况下替换成test1.txt里的内容。