<!DOCTYPE html> <html lang="en"> <head> <Meta charset="UTF-8"> <Meta name="viewport" content="width=device-width, initial-scale=1.0"> <Meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> function funget(){ var xhr; if(window.XMLHttpRequest){ xhr = new XMLHttpRequest; }else{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); } xhr.onreadystatechange = function (){ if(xhr.readyState == 4 && xhr.status == 200){ document.getElementById('content').innerHTML = xhr.responseText; } } xhr.open('GET','get.PHP',true); xhr.send(); } </script> <style> .root{ text-align: center } #content{ color: red; font-size: 30px; } </style> </head> <body> <div class="root"> <button onclick="funget()">点一下</button> <br><br><br> <div id="content"></div> </div> </body> </html>
页面是这样:
<?PHP echo 'GET方法<br>'; echo date('Y-m-d H:i:s',time()); ?>
这里是点击获取的时间,点击按钮后页面不会刷新,实现了局部的数据交互,显示为:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。