Ajax GET request for
Javascript/js:
<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's Ajax POST request:
<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 && xmlhtt p.status==200) {var d=xmlhttp.responsetext;//return value//processing return value}} </script>
Note: XMLHttpRequest is the basis of Ajax, when creating XMLHttpRequest objects, you must write the Ajax method in the same ' <script></script> ' tag! Otherwise, the AJAX request will go wrong and the data cannot be returned. JAVASCRIPT/JS Ajax Post/get Request.
The above discussion of JS native ajax,get and post is small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.