// ajax get pentalogy function ajax_get(url,data){ var ajax=new XMLHttpRequest();
//url method , If the sending data segment format is xxx.php?name=jack&age=18, Need stitching if(data){ url+='?'; url+=data;
}else{ } ajax.open('get',url); ajax.send(); ajax.onreadystatechange=function(){
if(ajax.readyState==4&&ajax.status==200){ console.log(ajax.responseText); } } }
function ajax_post(url,data){ var ajax=new XMLHttpRequest();
ajax.open('post',url);
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
if(data){ ajax.send(data); }else{ ajax.send(); }
ajax.onreadystatechange=function(){ if(ajax.readyState==4&&ajax.status==200){
console.log(ajax.responseText); } } } // take get and post Packaged together function
ajax_tool(url,data,method,success){ var ajax=new XMLHttpRequest();
if(method=='get'){ if(data){ url+='?'; url+=data; }else{ }
ajax.open(method,url); ajax.send(); }else{ //post The request does not need to be changed ajax.open(method,url);
ajax.setRequestHeader("Content-type","x-www-form-urlencoded"); if(data){
ajax.send(data); }else{ ajax.send(); } } ajax.onreadystatechange=function(){
if(ajax.readyState==4&&ajax.status==200){ console.log(ajax.responseText);
// Make data available to the outside world return ajax.responseText; // When onreadystatechange On call explain The data is back //
ajax.responseText; success(ajax.responseText); } } }
quote
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8">
<title>Document</title> </head> <body> <input type="button" value=" test get"
id="ajax_get"> </body> </html> <!-- Import encapsulated JS --> <script type="text/javascript"
src="ajax_tool.js"></script> <script type="text/javascript">
document.querySelector("#ajax_get").onclick=function(){ var
backData=ajax_tool('01.test_get.php','name=huluwa&&skill=saveyeye','get',function(data){
console.log(data); }); console.log(backData); } </script> <?php // obtain get Submitted data
echo $_GET['skill']; ?>

Technology