Jquery AJAX difference between POST and GET
- 2020-03-29 23:44:12
1:GET access browser thinks is idempotent
It's the same URL and there's only one result.
So on the second visit if the URL string doesn't change the browser simply pulls out the result of the first visit
POST is considered a mutable access (the browser thinks that the POST's submission must have changed)
To prevent idempotent access to GET by adding, right? + new Date (); , [so that the URL string is different for each visit]
You should also follow this principle when designing WEB pages
2: I talk about the difference between Get and Post in Ajax
The Get method:
Get is used to transfer simple data, but the size is generally limited to 1KB, and the data is appended to the url to send (HTTP header transmission), that is, the browser attaches each form field element and its data to the resource path in the request line according to the format of url parameters. Another important point is that it is cached by the client's browser so that someone can read the client's data, such as account Numbers and passwords, from the browser's history. Therefore, in some cases, the get method can cause serious security problems.
When POST is used, the browser sends each form field element and its data to the Web server as the entity content of the HTTP message, rather than as the parameter of the URL address. The amount of data transferred by POST is much larger than that by GET.
In a word, the GET method will be cached due to its small amount of data, high processing efficiency and low security, while the POST method will be the opposite.
Note about using get:
1 for get requests (or those involving url passing parameters), the passed parameters are processed by the encodeURIComponent method. Username =" +encodeURIComponent(username) + "&content=" +encodeURIComponent
(content) + & id = "1";
Note about using Post:
1. Set the contexttype of header to application/x-www-form-urlencode to ensure that the server knows that there are parameter variables in the entity. ). Ex. :
XmlHttp. SetRequestHeader (" the content-type ", "application/x - WWW - form - urlencoded");
Var name=abc&sex=man&age=18, var name=update.php?
Abc&sex =man&age=18 and var name=? Abc&sex =man&age=18 is all wrong;
3. Parameters are sent in the Send(parameter) method, for example: xmlhttp.send (name); If it is a get mode, directly xmlhttp.send (null);
4. Server-side request parameters distinguish Get from Post. $username = $_GET["username"]; If post mode is used, $username = $_POST["username"];
AJAX garbled code problem
Causes of garbled codes:
1. The default character encoding of the data returned by XTMLHTTP is utf-8. If the client page is gb2312 or other encoding data, garrages will be generated
2. The default character encoding of post method submission data is utf-8. If the server is gb2312 or other encoding data, it will generate scrambled codes
1. If the client is gb2312 code, the output stream code is specified in the server
2. Both the server side and the client side use utf-8 encoding
Gb2312: header (' the content-type: text/HTML. Charset = GB2312 ');
Utf8: header (' the content-type: text/HTML. Charset = utf-8 ');
Note: If you have already done the above method and still return a gargle, check if your method is get. For get requests (or those involving url passing parameters), the parameters passed must be processed by the encodeURIComponent method.