使用Ajax在HTML頁面中局部刷新頁面(左邊菜單右邊頁面)


轉載自:https://blog.csdn.net/Cenmen_17714/article/details/80969008

 

index.html

<a href="javascript:void(0);" οnclick="loadXMLDoc('member.html')">查看用戶</a>
<div id="mainbody">歡迎登錄!</div>

index.html中的Ajax代碼

 
 1 <script>
 2 function loadXMLDoc(url)
 3 {
 4   var xmlhttp;
 5   if (window.XMLHttpRequest)
 6   {
 7     //  IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執行代碼
 8     xmlhttp=new XMLHttpRequest();
 9   }
10   else
11   {
12     // IE6, IE5 瀏覽器執行代碼
13     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
14   }
15   xmlhttp.onreadystatechange=function()
16   {
17     if (xmlhttp.readyState==4 && xmlhttp.status==200)
18     {
19       document.getElementById("mainbody").innerHTML=xmlhttp.responseText;
20     }
21   }
22   xmlhttp.open("GET",url,true);
23   xmlhttp.send();
24 }
25 </script>

 

執行效果前的頁面展示:

 

 

點擊查看用戶執行js后的頁面:

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM