Home >Backend Development >PHP Tutorial >ajax2—php (28), ajax2php28_PHP tutorial
8 Use post to transfer data
l xmlhttp.open("post","action.php");
l xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
l xmlhttp.send(data);
1. What are the differences between get and post requests?
Transfer data size is different:
Get:2k
Post: original limit
Different ways of transmitting data:
Get: behind url
Post: after a blank line
Transfer data formats are different:
Get: text string
Post: text string, binary
Get request:
Post request:
Php code:
The packet capture results are as follows:
As you can see from the picture above, this http request
1) Post request
2) Use content-type request header
3) The parameters are placed after the blank line
I made some modifications to the php code in the above question and found that the latest results can be returned immediately.
Post requests will not cause caching issues.
Example question:
Use Ajax to complete data entry
9. Application of xml in ajax
In ajax, for simple returned data, we can use responseText to get the value
For large batches and complex data, xml or json technology needs to be used
Corresponding parsing code:
l var xml=xmlHttp.responseXML;
l node=xml.getElementByTagName(“TagName”);
l node[0].childNodes[0].nodeValue;