1:index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "UTF-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>ajax Getting Started </title>
<script type= "Text/javascript" >
Window.onload=function () {
1. Get the A node and add the onclick response function to it
document.getElementsByTagName ("a") [0].onclick=function () {
3. Create a XMLHttpRequest Object
var request=new xmlhttprequest ();
4. Prepare the data for sending the request: URL and method of sending the request
var url=this.href;
var method= "GET";
5. Call the Open method of the XMLHttpRequest object (open link)
Request.open (method, URL);
6. Call the Send method of the XMLHttpRequest object (send data)
Request.send (NULL); The data for the GET request is immediately following the URL
7. Add onreadystatechange response functions for XMLHttpRequest objects
Request.onreadystatechange=function () {
8. Determine if the response is complete: When the ReadyState property value of the XMLHttpRequest object is 4
if (request.readystate==4) {
9. Re-determine if the response is available: XMLHttpRequest object when the Status property value is 200 or 304
if (request.status==200| | request.status==304) {
10. Print response Result: responsetext
alert (Request.responsetext);
}
}
}
2. Cancel the A node default behavior
return false;
}
}
</script>
<body>
<a href= "HelloAjax.txt" >HelloAjax</a>
</body>
2:helloajax.txt
helloajax! ^^