1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 <script> 7 function loadXML(){ 8 var xmlhttp; 9 if(window.XMLHttpRequest){ 10 // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码 11 xmlhttp=new XMLHttpRequest(); 12 } 13 else{ 14 // IE6, IE5 浏览器执行代码 15 xmlhttp=ActiveXObject("Microsoft.XMLHTTP"); 16 } 17 xmlhttp.onreadystatechange=function(){ 18 if(xmlhttp.readyState==4&&xmlhttp.status==200){ 19 document.getElementById("myDiv").innerHTML=xmlhttp.responseText; 20 } 21 } 22 xmlhttp.open("GET","fg.txt",true); 23 xmlhttp.send(); 24 } 25 </script> 26 <body> 27 <div id="myDiv"> 28 使用ajax修改该文本内容 29 </div> 30 <button type="button" onclick="loadXML()">点击修改</button> 31 </body> 32 </html>