The difference between get and post in AJAX in PHP
Get:
can transmit simple data in get mode, but the size is generally limited to 1KB, and the data is sent to URL (header transmission of HTTP), that is, the browser attaches the various form field elements and their data to the resource in the request line according to the format of the URL parameters. Behind the path. The other most important thing is that it will be cached by the client's browser, so that other people can read the client's data from the browser's history, such as accounts and passwords. Therefore, in some cases, the get method can cause serious security problems. The
Post mode:
when using the POST mode, the browser sends the form field elements and their data to the Web server as the HTTP message, rather than as a parameter of the URL address, and the amount of data passed by the POST mode is much larger than the amount of data transmitted by the GET mode.
in short, GET mode can transmit data with small amount, high processing efficiency, low security, and will be cached, whereas POST will not.
needs to be noted in the way of get:
1 for get requests (or to URL passing parameters), the transmitted parameters must first be processed by encodeURIComponent method. > (content).Quot;.Amp; id=1.quot;
use the Post mode to pay attention to:
1. set header Context-Type for application/x-www-form- considerations to ensure that the server knows the parameter variables in the entity. Urlencoded;.Quot;).
xmlHttp.setRequestHeader (.Quot; Content-Type.quot;.Quot; application/x-www-form-urlencoded.quot;); the
2. parameter is a pair of key values corresponding to the name / value, and each pair of values is separated by the.Amp; the number is separated by the VaR name=abc.amp; sex=man.amp; =? Abc.amp; sex=man.amp; age=18 writing is wrong; the
3. parameter is sent in the Send (parameter) method, for example, xmlHttp.send (name); if get is the way, the direct xmlHttp.send (null); If it is a get mode, $username = $_GET[.quot; username.quot;]; if it is a post mode, $username = $_POST[.quot; username.quot;];
Post and Get methods have the following difference: when the data is transmitted, it does not need to be displayed in it, and the method is to be displayed in it.
2.Post transfers a large amount of data and can reach 2M, and the Get method can only pass about 1024 bytes of.
3.Post due to the limit of URL length. In order to transfer data to the server segment, Get is to get data from the server segment. And Get is also able to transmit data, only to design and tell. Server, what data do you really need,.Post information as the content of the HTTP request, and Get is transmitted on the Http header. The
get method uses Request.QueryString[.quot; strName.quot;] receive the
post method with Request.Form[.quot; strName.quot;] receive
note:
although two submissions can be unified with Request (.Quot;) to obtain the data, but it has an impact on the efficiency of the program and is not recommended.
generally, try to avoid submitting a form using Get as possible, because it may cause the
AJAX code problem of the security problem
the cause of the chaotic code: the default character encoding of the data returned by
1 and xtmlhttp is UTF-8, and if the client page is GB2312 or other encoded data, the chaotic code
2, the post method submits data by default character encoding is UTF-8, if the server side is GB2312 or other encoded data will produce a random code
solution is:
1, if the client is GB2312 encoding, then the server specified output stream encoded
2, the server side and the client side use UTF-8 encoded
gb2312:header (' Content-Type:text/html; charset=GB2312');
utf8:header ('Content-Type:text/html; charset=utf-8');
note: if you have done it in the above method, or return to the code, check if your way is get, for the get request (or to the URL passing the parameter), the passed parameters must first pass the e NcodeURIComponent processing. If you do not use encodeURIComponent, you will generate garbled code.