This article is about the difference between Ajax post and get in jquery. Has carried on the detailed summary introduction, needs The friend may come over the reference, hoped to be helpful to everybody
The 1:get Access browser thinks that a power is equal to the same URL with only one result [same as the entire URL string exactly matches] so the second time when the URL string does not change the browser is directly out of the results of the first visit
Post is considered to be a variable access (the browser thinks that post commits must be changed)
Prevent idempotent access to get add after URL? +new Date ();, [in short, the URL string for each access is different]
You should also follow this principle when designing Web pages.
2: one. Talk about the difference between the get and post of Ajax
Get mode: use the Get method to transfer simple data, but the size is generally limited to 1KB, the data is appended to the URL to send (HTTP header transfer), that is, The browser attaches individual form field elements and their data behind the resource path in the request line in the format of the URL parameter. The most important point is that it will be cached by the client's browser, so that others can read the customer's data from the browser's history, such as the account number and password. Therefore, in some cases, the Get method poses a serious security problem.
Post mode: when using post, the browser sends each form field element and its data to the Web server as the entity content of the HTTP message, instead of being passed as a URL address parameter. The amount of data passed by post is much larger than the amount of data sent using get.
In short, the Get method transmits small amounts of data, high processing efficiency, low security, will be cached, and post instead.
use the Get method to note: 1 for a GET request (or any that involves a URL pass parameter), the passed arguments are first handled by the encodeURIComponent method. Example: var url = "Update.php?username=" + encodeURIComponent (username) + "&content=" +encodeuricomponent
(content) + "&id=1";
use the Post method to be aware of: 1. Set the header's Context-type to Application/x-www-form-urlencode to ensure that the server knows that there are parameter variables in the entity. The setRequestHeader ("Context-type", "application/x-www-form-urlencoded;") of the XMLHttpRequest object is usually used. Cases:
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); 2. The parameter is the key value pair corresponding to the name/value one by one, separated by the & number for each pair. As Var name=abc&sex=man&age=18, pay attention to Var name=update.php?
Abc&sex=man&age=18 and the name=?abc&sex=man&age=18 of Var are all wrong; 3. The parameters are sent in the Send (parameter) method, for example: Xmlhttp.send (name); If it is get mode, direct xmlhttp.send (NULL);
4. The server-side request parameter distinguishes between get and post. If it is GET mode then $username = $_get["username"]; If it is POST mode, then $username = $_post["username"];
Ajax garbled problem
garbled reasons: 1, Xtmlhttp returned by default character encoding is Utf-8, if the client page is gb2312 or other encoded data will be garbled 2, POST method submission data default character encoding is Utf-8, If the server side is gb2312 or other encoded data will produce garbled
The workaround is: 1, if the client is GB2312 encoding, the server specifies the output stream encoding 2, the server side and the client use 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 whether your way is get, for the GET request (or all involved in the URL to pass parameters), the passed parameters must be preceded by the encodeURIComponent method processing. If not treated with encodeuricomponent, it will also produce garbled characters.
RPM: The difference between Jquery AJAX post and get