How Ajax sends data for GET requests

Source: Internet
Author: User

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! ^^

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.