Jquery AJAX Post and get difference __jquery

Source: Internet
Author: User

1:get Access Browser thinks it's idempotent.
The same URL has only one result [the same is the exact match of the entire URL string]
So the second visit if the URL string does not change the browser is directly come up with the results of the first visit

Post is considered a variable access (the browser believes that the Post's submission must be changed)

To prevent the equal power access of get is added after the URL. +new Date ();, [in short, to make each access URL string different]

You should also follow this principle when designing Web pages.

2: I. Talking about the difference between get and post of Ajax

Get Way:
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.

Post method:
When using post, the browser sends individual form field elements and their data to the Web server as the entity content of the HTTP message, rather than as a parameter to the URL address, and the amount of data that is passed by post is much larger than the amount of data that is transmitted using the GET method.

In short, get-mode transfer data is small, high processing efficiency, low security, will be cached, and post instead.

You need to be aware of using get methods:
1 for Get requests (or any that involve passing parameters to the URL), the passed parameters are processed first by the encodeURIComponent method. Example: var url = "Update.php?username=" +encodeuricomponent ( username) + "&content=" +encodeuricomponent

(content) + "&id=1";


Use POST method to note:
1. Set header Context-type to Application/x-www-form-urlencode ensure that the server knows that there are parameter variables in the entity. Usually use the setRequestHeader ("Context-type", "application/x-www-form-urlencoded;") of the XMLHttpRequest object. Cases:

Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
2. The parameter is a name/value one by one corresponding to the key value pairs, each pair of values separated by the & number. like Var name=abc&sex=man&age=18, pay attention to Var name=update.php?

The abc&sex=man&age=18 and the Var name=?abc&sex=man&age=18 are all wrong;
3. Parameters sent in the Send (parameter) method, example: Xmlhttp.send (name); If it is a get way, direct xmlhttp.send (NULL);

4. Server-side request parameters differentiate get and post. If the Get method is $username = $_get["username"]; If it is the POST method, then $username = $_post["username"];

Ajax garbled problem

The reason for the garbled:
1, Xtmlhttp returned the data default character encoding is Utf-8, if the client page is gb2312 or other encoded data will produce garbled
2, Post method submission data default character encoding is utf-8, if server-side is gb2312 or other encoded data will produce garbled
Solutions include:
1, if the client is gb2312 code, then specify the output stream code on the server
2, server-side and client are using UTF-8 encoding

Gb2312:header (' content-type:text/html;charset=gb2312 ');

Utf8:header (' Content-type:text/html;charset=utf-8 ');

Note: If you have done the above method, or return garbled words, check your way is get, for get requests (or where the URL is involved in passing parameters), the parameters are passed first encodeURIComponent method is processed. If not treated with encodeuricomponent, it will produce garbled characters.

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.