原生js版ajax请求

    function getXMLHttpRequest() {  
              var xhr;  
              if(window.ActiveXObject) {  
                       xhr= new ActiveXObject("Microsoft.XMLHTTP");  
              }else if (window.XMLHttpRequest) {  
                       xhr= new XMLHttpRequest();  
              }else {  
                       xhr= null;  
              }  
              return xhr;  
    }  
      
    function save() {  
              var xhr = getXMLHttpRequest();  
              xhr.open("post","url");  
              var data = "name=mikan&address=street...";  
              xhr.send(data);  
              xhr.onreadystatechange= function() {  
                       if(xhr.readyState == 4 && xhr.status == 200) {  
                                alert("returned:"+ xhr.responseText);  
                       }  
              };  
    } 
原文地址:https://www.cnblogs.com/gaocong/p/5018604.html