<%-- Created by IntelliJ IDEA. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>这是一个ajax的demo</title> <script type="text/javascript"> window.onload = function () { document.getElementsByTagName("a")[0].onclick = function () { //1.创建XMLHttpRquest对象 var request = new XMLHttpRequest(); // 2.调用XMLHttpRequest对象的open()方法 request.open("GET","hello.txt"); // 3.调用对象的send方法 request.send(null); //为对象添加onreadystatechange响应函数 request.onreadystatechange = function () { // 4.判断响应是否可用,然后做响应的操作 if (request.readyState == 4) { if (request.status == 200 || request.status == 304) {
//弹出响应文本中的内容 alert(request.responseText); } } } return false; } } </script> </head> <body> <a href="hello.txt">点击我</a> </body> </html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。