The Ajax GET request code for the
Javascript/js is as follows:
<script type= "Text/javascript" > * * Create XMLHttpRequest Object * * var xmlHttp; function Getxmlhttpobject () {if (window).
XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest ();
}else{//code for IE6, IE5 xmlhttp=new activexobject ("Microsoft.XMLHTTP");
return XMLHTTP;
//-----------Ajax method-----------//function Getlabelsget () {xmlhttp=getxmlhttpobject (); if (xmlhttp==null) {alert (' Your browser does not support ajax!
');
Return
var id = document.getElementById (' id '). value;
var url= "http://www.Leefrom.com?id=" +id+ "&t/" +math.random ();
Xmlhttp.open ("Get", url,true);
Xmlhttp.onreadystatechange=favorok;//sends the event, receives the information to call the function xmlhttp.send (); function Getokget () {if (xmlhttp.readystate==1| | xmlhttp.readystate==2| | xmlhttp.readystate==3) {//local prompt: Load in} if (xmlhttp.readystate==4 && xmlhttp.status==200) {var d= xm
Lhttp.responsetext; Processing return results}} </script>
Javascript/js POST request for Ajax:
<script type= "Text/javascript" >/* Create XMLHttpRequest Object * * var xmlHttp; function Getxmlhttpobject () {if (window).
XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest ();
}else{//code for IE6, IE5 xmlhttp=new activexobject ("Microsoft.XMLHTTP");
return XMLHTTP;
//-----------Ajax method-----------//function Getlabelspost () {xmlhttp=getxmlhttpobject (); if (xmlhttp==null) {alert (' Your browser does not support ajax!
');
Return
var url= "http://www.lifefrom.com/t/" +math.random ();
Xmlhttp.open ("POST", url,true);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (); xmlhttp.onreadystatechange=getlabelsok;//after sending the event, you receive the message Call function} function Getokpost () {if xmlhttp.readystate==1| | xmlhttp.readystate==2| | xmlhttp.readystate==3) {//local prompt: Load/process} if (xmlhttp.readystate==4 && xmlhttp.status==200) {var d=xmlhttp.res Ponsetext; return value//processing return value}} </script>
Note: XMLHttpRequest is the basis of Ajax, and when creating XMLHttpRequest objects, you must be in the same ' <script></script> ' tag as the Ajax method you write! Otherwise, the AJAX request will go wrong and the data cannot be returned. JAVASCRIPT/JS Ajax Post/get Request.
The above is a small set to introduce the original JS Ajax,get and POST request instance code related 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!