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
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>
<div id= "php100" ></div>
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:
?
echo $_post[' text '];
? >
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 js+ajax,get and post in the use of the difference is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.