GET request for ajax 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; } // -----------------------// 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;//After sending the event, the message was received. The call function xmlHttp.send(); }function getOkGet(){ if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ // Local prompt: Loading} if (xmlHttp.readyState==4 && xmlHttp.status==200){ var d= xmlHttp.responseText; // Processing returns the result} } </script>POST request for ajax 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; } // -----------------------// 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, the message was received, calling the function} function getOkPost(){ if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ // Local prompt: Loading/processing} if (xmlHttp.readyState==4 && xmlHttp.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 be in the same '<script></script>' tag as the ajax method you wrote! Otherwise, the ajax request will error and the data will not be returned. javascript/js ajax POST/GET request.
The above brief discussion of JS native Ajax, GET and POST is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.