Ajax加载更多效果

    xiaoxiao2022-07-13  146

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <div id="box"></div></br> <input type="button" value="加载" id="btn"></br> </body> </html> <!-- 加载更多 --> <script> let oBox=document.getElementById("box"); let oBtn=document.getElementById("btn"); function LoadMore(page){ let xhr=new XMLHttpRequest(); xhr.open("GET","LoadMore.php?page="+page,true); xhr.onreadystatechange=function(){ if(xhr.status==200 && xhr.readyState==4){ oBox.innerHTML+=xhr.responseText+"</br>"; } } xhr.send(); } LoadMore(1); oBtn.onclick=function(){ LoadMore(2); this.style.display="none"; } </script>

    php代码

    <?php header("Content-type:text/html;charset=utf-8"); $page=$_GET["page"]; if($page==1){ echo 11111; } else if($page==2){ echo 22222; } ?>
    最新回复(0)