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