原生JS实现ajax发送GET 和 POST请求
GET请求
var recharge_url = "https://ad.oceanengine.com/agent/api/query_bill/?start_date=2015-01-01&end_date=2019-08-13&field=name&q=&type=";
     var xhr;
     if (window.XMLHttpRequest) { // 其他类型的浏览器
         xhr = new XMLHttpRequest();
     } else { // ie浏览器
         xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
     var xhr2 = new XMLHttpRequest();
 
     // 2:配置请求信息
     xhr.open('get', recharge_url, true);
     // 3:发送请求
     xhr.send();
     // 4:监听状态 注册onreadystatechange事件
     xhr.onreadystatechange = function() {
         // 5:判断请求和相应是否成功
         if (xhr.readyState == 4 && xhr.status == 200) {
             // 6:获取数据 并做相应的处理
             var data = xhr.responseText; 
             console.log('扩展输出get:',data);
         }
    }
POST请求
<script>
var oStr = '';
var postData = {};
var oAjax = null;
//post提交的数据
postData = {"name1":"value1","name2":"value2"};
//这里需要将json数据转成post能够进行提交的字符串  name1=value1&name2=value2格式
postData = (function(value){
  for(var key in value){
    oStr += key+"="+value[key]+"&";
  };
  return oStr;
}(postData));
//这里进行HTTP请求
try{
  oAjax = new XMLHttpRequest();
}catch(e){
  oAjax = new ActiveXObject("Microsoft.XMLHTTP");
};
//post方式打开文件
oAjax.open('post','1.php?='+Math.random(),true);
//post相比get方式提交多了个这个
oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//post发送数据
oAjax.send(postData);
oAjax.onreadystatechange = function(){
  //当状态为4的时候,执行以下操作
  if(oAjax.readyState == 4){
    try{
      alert(oAjax.responseText);
    }catch(e){
      alert('你访问的页面出错了');
    };
  };
};
</script>