使用Ajax在HTML頁面中區域性重新整理頁面(左邊選單右邊頁面)
阿新 • • 發佈:2019-01-05
index.html
<a href="javascript:void(0);" onclick="loadXMLDoc('member.html')">檢視使用者</a>
<div id="mainbody">歡迎登入!</div>
index.html中的Ajax程式碼
<script> function loadXMLDoc(url) { var xmlhttp; if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執行程式碼 xmlhttp=new XMLHttpRequest(); } else { // IE6, IE5 瀏覽器執行程式碼 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mainbody").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET",url,true); xmlhttp.send(); } </script>
執行效果前的頁面展示:
點選檢視使用者執行js後的頁面: