Examples of the use of XMLHttpRequest to communicate with the server contains the following three key components:
-onreadystatechange time time event handler (with server triggers, each readystate property change event will trigger readystatechange)
-open method
-send method
There are five values readystate property 01234
<%-- 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"); request.send (the send method 3. Call object//null ); // add object onreadystatechange response function request.onreadystatechange = function () { // 4. Analyzing the response is available, then do operation response of IF (request.readyState ==. 4 ) { IF (== request.status == 304 || request.status 200 is ) { // pop up in response to the text content Alert (request.responseText); } } } return to false ; } } </ Script> </ head> <body> <a the href = " hello.txt "> click me </a> </ body> </ HTML>