原生js实现ajax请求,添加请求头

function ajax(){
    //1.创建ajax对象

    if(window.XMLHttpRequest){
        oAjax=new XMLHttpRequest();
    }else{
        oAjax=new ActiveXObject("Microsoft.XMLHTTP");
    }
    oAjax.open('GET',"./index.do", true);
   oAjax.setRequestHeader("Authorization",token);  //设置请求头
    oAjax.send(null);
    oAjax.onreadystatechange=function(){
         "要执行的操作"
}

猜你喜欢

转载自blog.csdn.net/qq_42091922/article/details/86062240