搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
AJAX 教程
AJAX 基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>AJAX 发送请求示例 - 基础教程(div.cn)</title> <body> <h2>AJAX GET 请求</h2> <button type="button" onclick="fetchDoc()">获取内容</button> <div id="output"></div> <script> function fetchDoc() { var httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { document.getElementById("output").innerHTML = this.responseText; } }; httpRequest.open("GET", "ajax_get.php", true); httpRequest.send(); } </script> </body> </html>
运行结果