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 is the detailed explanation of the use of JS, Ajax Get and Post that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!