The biggest difference between get and post methods is:
1. The get method passes the value parameter in the url, and the post parameter is placed in the send
2. The post method must be added
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
The following examples can be found in the get method
xmlHttp.open("GET","for.php?text="+url,true);In post, it is represented as:
xmlHttp.open("POST","for.php",true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");POST and GET methods share 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; //For multiple parameters, 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 summary of the difference between Js+Ajax, Get and Post in terms of usage is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.