<!DOCTYPE html> <html lang = "zh-CN"> <head> <Meta charset = "UTF-8"> <title>ajax实现异步请求</title> </head> <body> <button type="button" id="button">异步请求发送按钮</button> <script> var elementById = document.getElementById("button"); elementById.addEventListener("click", function (event) { // 创建 XMLHttpRequest 对象,检测 IE5、IE6的兼容性问题 var xml_http = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); // 请求类型 URI地址 异步请求 xml_http.open("GET", "/WebSecond_war_exploded/hello", true); // 发送请求 xml_http.send(); xml_http.onreadystatechange=function() { if (xml_http.readyState==4 && xml_http.status==200) { var responseText = xml_http.responseText; alert(responseText); } } }) </script> </body> </html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。