Get and POST requests are different:
1, to the server to pass the amount of data:
Get up to 2k
Post is not limited in principle, php.ini is limited to 8m
2, the transmission of data in a different form:
Get passes parameters in the form of a request string after a URL address
Index.php?name=francis&age=25
Post is to send the form form's data to the request in the form of XML passed to the server
3, Post more secure
Ajax Initiation Request steps:
1. Creating an Ajax object: XHR
2. Create HTTP request: equivalent to open browser input address
Xhr.open (Request method, request address [, asynchronous/Synchronous request]);
3, send the request: equivalent to enter the address and then press ENTER
Xhr.send (POST request data/get is null);
Get requests require considerations:
1, get requests to pass the data written at the request address, in the form of a request string
2, Chinese = & and other special symbols need to encode processing
Scenario Example: real-time determination of whether a user name can be registered
If the user name is Username= "francis&age=25", use Get method to send the request, request the address "index.php?name=" +username, this time the actual address is index.php?name= francis&age=25 results in 2 parameters passed
The workaround is: PHP: Encode/Deserialize data using function UrlEncode ()/urldecode ()
JS: Encode data with function encodeuricomponent ()
These two coding functions are to make the data become% and then add 2 hexadecimal digits.
Can be directly received on the server side without the need for anti-coding processing
Post requests require considerations:
1, the POST request needs to pass the data writes in the Send () method, is also the request string format
2, the use of post data is the essence of copying form form to the server to pass data, and form form to the server to pass data in the format of XML, so you need to pass the post data, that is, the Send () method of the request string, organized into XML format
Use the setRequestHeader () method to set header header information and organize the data into XML format:
Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');//This method is immediately followed by the Xhr.open () method
3, the transmission of data if there is Chinese & = and other special symbols still need to encode
4, using post to pass data can also be used in the request address to pass data in the Get