The difference between the Open method post and get parameter under Ajax XMLHTTP

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

1. Get is to obtain data from the server (will expose the client IP), post is to send data to the server.
2. Get is to add the parameter data queue to the URL of the action attribute that submits the form, and the value corresponds to each field one by one in the form, which can be seen 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.
3. 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.
4. The amount of data transferred by get is small and cannot be greater than 2KB. Post transfers have a large amount of data, which is generally default to unrestricted. In theory, however, the maximum number of IIS4 is 100KB in 80KB,IIS5.
5. Get security is very low, post security is high. But the execution efficiency is better than the Post method.

Suggestions:

1, get mode of security is less than the Post method, including confidential information, the proposed use of post data submission method;
2, in doing the data query, it is recommended to use get way, while doing data add, modify or delete, the proposed post method;


1 Problem Description:
Xmlhttp:open method, when the page is requested, update the page data, the 2nd time to get the results or last information
2 Solutions:
Use post mode instead
3 Description:
Xmlhttp:open method
Creates a new HTTP request and specifies the method, URL, and authentication information for this request
Grammar

Oxmlhttprequest.open (Bstrmethod, bstrURL, Varasync, Bstruser, bstrpassword);
Parameters

Bstrmethod
HTTP methods, for example: POST, get, put, and propfind. Not sensitive to case.
/*****
Post: Send the data in "post" mode, can be as large as 4MB
Get: Send data in "Get" mode, only 256KB
If you request a practical post method with parameters, the Post method places the parameters inside the hidden control of the page
No parameters using Get method
It is also best to post a page that may change in the middle of the request
You may not be able to get the most up-to-date information with the Getting method
*****/
bstrURL
The URL address of the request, which can be either an absolute address or a relative address.
varasync[Optional]
Boolean, specifying whether this request is asynchronous and true by default. If true, the callback function specified by the onReadyStateChange property is invoked when the state changes.
bstruser[Optional]
If the server requires authentication, the user name is specified here, and if not specified, the validation window pops up when the server needs to authenticate.
bstrpassword[Optional]
The password portion of the authentication information, which is ignored if the user name is empty.

Example

The following example demonstrates requesting book.xml from a server and displaying the book field in it.

The code is as follows Copy Code

var xmlhttp = new ActiveXObject ("msxml2.xmlhttp.3.0");
Xmlhttp.open ("Get", "http://localhost/books.xml", false); Use get with no parameters and no change, otherwise use post
Xmlhttp.send ();
var book = Xmlhttp.responseXML.selectSingleNode ("//book[@id = ' bk101 ']");
alert (book.xml);

Note

After calling this method, you can call the Send method to send data to the server.

Call page

The code is as follows Copy Code

<script language= "javascript" type= "Text/javascript" >
function UpdateData ()
{
var serverurl = window.location.href;
var str = serverurl.split ("/");
var ServerURL = "http://" +str[2];
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
var serverurl=serverurl+ "/gettemp.aspx";
xmlHTTP. Open ("POST", ServerURL, false);
xmlHTTP. Send ("ADST");
XMLHTTP = null;
}
</script>

Process the page and get the incoming data

  code is as follows copy code

Private String GetInput ()
{
System.IO.Stream s = request.inputstream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder ();
while ((count = s.read (buffer, 0, 1024)) > 0)
{
Builder. Append (Encoding.UTF8.GetString (buffer, 0, count));
}

Return builder. ToString ();
}

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.