The biggest difference between get and post methods is that:
The 1.get method passes the value parameter inside the URL, and the post parameter is sent inside the send
2.post method must be added
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
The following example looks at the Get method
Xmlhttp.open ("Get", "for.php?text=" +url,true);
The post is displayed as:
Xmlhttp.open ("POST", "for.php", true);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Post and Get methods Common files
index.php
<script src= "A.js" type= "Text/javascript" ></script>
<a href= "#" onclick= "funphp100 (' O ')" >o </a>
<a href= "#" onclick= "funphp100 (' t ')" >t</a>
<a href= "#" onclick= "funphp100 (' x ')" >x</a>
Post Method File:
A.js
var xmlHttp;
function S_xmlhttprequest () {
if (window). ActiveXObject) {
xmlhttp=new activexobject (' microsoft.xmlhttp ');
} else if (window. XMLHttpRequest) {
xmlhttp=new XMLHttpRequest ();
}
}
function funphp100 (n) {
var data = "text=" +N; Multiple parameters, then add
s_xmlhttprequest ();
Xmlhttp.open ("POST", "for.php", true);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange=byphp;
Xmlhttp.send (data);
}
function byphp () {
var byphp100=xmlhttp.responsetext;
document.getElementById ("php100"). innerhtml=byphp100;
for.php:
Get method File:
A.js:
var xmlHttp;
function S_xmlhttprequest () {
if (window). ActiveXObject) {
xmlhttp=new activexobject (' microsoft.xmlhttp ');
} else if (window. XMLHttpRequest) {
xmlhttp=new XMLHttpRequest ();
}
}
function funphp100 (URL) {
s_xmlhttprequest ();
Xmlhttp.open ("Get", "for.php?text=" +url,true);
xmlhttp.onreadystatechange=byphp;
Xmlhttp.send (null);
}
function byphp () {
var byphp100=xmlhttp.responsetext;
document.getElementById ("php100"). innerhtml=byphp100;
for.php:
?
echo $_get[' text '];
? >
The above is a small set to introduce JS and Ajax get and post in the use of different examples of the relevant knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!