Get and POST requests in Ajax

Source: Internet
Author: User
Tags end header html header http post

Learning Ajax technology, a lot of students in Ajax get and post requests are always puzzled, in order to give students to solve the problem, will be in the teaching of the Get and POST request summary published in the student base camp, hoping to bring you help.
In the introduction of Ajax I also briefly introduced the differences between the use of them, in order to enable students to fully understand, as the summary of the lectures are published below.
first, get () and post () Basic difference
1.get is to add the parameter data queue to the URL that refers to the action attribute of the submission form, and the value corresponds to each field one by one in the form, as you can see in the URL. Post is the HTTP post mechanism that places the fields in the form and their contents in the HTML header to the URL address that the action attribute refers to. This process is not visible to the user.
2. For Get way, server end uses Request.QueryString to obtain variable value, for post way, server end uses Request.Form to obtain the submitted data. The parameters of both methods can be obtained by request.
3.get transmits a small amount of data, not greater than 2KB. Post transfers have a large amount of data, which is generally default to unrestricted. In theory, however, it varies depending on the server.
4.get security is very low and post security is high.
5.<form method= "Get" action= "A.asp?b=b" > with <form method= "get" action= "a.asp" > is the same, that is to say, The list of arguments behind the action page when method is get is ignored, while <form method= "post" action= "A.asp?b=b" > and <form method= "Post action=" A.asp "> is not the same.

Ii. talking about the difference between get and post of Ajax
1.Get Mode
You can transfer simple data in Get mode, but the size is typically limited to 1KB, the data is appended to the URL (HTTP header transfer), that is, the browser appends individual form field elements and their data to the resource path in the request line in the format of the URL parameter. The most important point is that it is cached by the client's browser, so that other people can read the customer's data, such as account number and password, from the browser's history. Therefore, in some cases, the Get method poses a serious security problem.
Ajax Send Request: If it is a GET request send (parameter) parameter: must be null or xhr.send ();
Get requests do not have to set Xhr.setrequestheader (Header,value)
Note: if xhr.send (parameter); If the parameter is not empty, it will be automatically converted to post in some browsers you can get the way you requested by Request.getmethod ();
Instance:
function Getajax () {

Get XHR Object
var xhr = getxhr ();
Specify the type of request
Xhr.open ("Get", "main.jsp?username=123", true);
Send Request
Xhr.send ();
Handling Server Response Events
Xhr.onreadystatechange = function () {
Interpretation of whether the processing completed and interpretation of the server is successful!
if (xhr.readystate==4 && xhr.status==200) {
alert (Xhr.responsetext);
}
}
}
}
Using GET method requires attention

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.