HTML Ajax實現分頁代碼:
<script type="text/javascript"> function loadPage(page){ //設置ajax請求 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4 && xhr.status == 200){ //處理數據 var data = xhr.responseText; //將數據渲染到頁面上 document.getElementById("myTable").innerHTML = data; } } //發送ajax請求 var url = "getData.php?page=" + page; xhr.open("GET", url, true); xhr.send(); } </script> <table id="myTable"> <tbody> <tr> <td>1</td> <td>張三</td> <td>20</td> </tr> <tr> <td>2</td> <td>李四</td> <td>25</td> </tr> <tr> <td>3</td> <td>王五</td> <td>30</td> </tr> </tbody> </table> //html中的分頁代碼 <div class="pager"> <a href="javascript:loadPage(1);">首頁</a> <a href="javascript:loadPage(2);">上一頁</a> <a href="javascript:loadPage(3);">下一頁</a> <a href="javascript:loadPage(4);">尾頁</a> </div>