Ajax.js

  原生js   Ajax的插件   将其封装起来

  function ajax(method,url,boo,fn){
    //创建Ajax的实例对象
    var xmlhttp=new XMLHttpRequest();
    //像后台发送请求
    xmlhttp.open(method,url,boo);
    //发送
    xmlhttp.send()
    //向服务器响应;
    xmlhttp.onreadystatechange=function(){
      if(xmlhttp.readyState==4 && xmlhttp.status==200){
        //说明与服务器发送响应也成功了
        fn(xmlhttp.responseText)
      }
    }
  }

  使用手册

  ajax("get","cont.txt",true,ff);
  function ff(data){
    var arr=JSON.parse(data);
    document.getElementById("div").innerHTML+=arr[0].name;
  }

原文地址:https://www.cnblogs.com/shangjun6/p/10483438.html