首页 > 代码库 > ajax 代码

ajax 代码

function ajax(){

  var aj=null;

  if(window.ActiveXObject){

    aj = new ActiveXObject("Microsoft.XMLHTTP");

  }else if(window.XMLHttpRequest){

    aj = new XMLHttpRequest();

  }

  aj.onreadystatechange = function(){

    if(aj.readyState==4){

      if(aj.status==200){

        console.log(aj.responseText)

      }

    }

  }

//get 方式提交;

    aj.open("get",/文件路径);

    aj.send();

//post 方式提交

    aj.open("post","/文件路径");

    var 变量= “name=”+value,"&psd="+value

    aj.setRequestHeader("Content-type","application/x-www-from-urlencoded");

    aj.send(变量);

}

ajax 代码