• 原生ajax与jquery ajax #请求头的设置方法


            $.ajax({
                type:"get",
                url: "http://localhost/user/test",
                headers: {
                  "Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdLCJ1c2VyX25hbWUiOiJ7XCJlbWFpbFwiOlwiMjExOTI5OTUzMUBxcS5jb21cIixcImZ1bGxuYW1lXCI6XCLlsI_luoRcIixcImlkXCI6MyxcInBhc3N3b3JkXCI6XCIkMmEkMTAkc1o4d0d4NHkvcG1CM1g4QkFGZWxTLmpqR2M2TE8weDluMWFzR1cvWEVPT2VQMGF1dmFkSnFcIixcInVzZXJuYW1lXCI6XCIxODQ3NjMwNTY0MFwifSIsInNjb3BlIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiLCJST0xFX0FQSSJdLCJleHAiOjE2MjM4Mzc4MDUsImF1dGhvcml0aWVzIjpbImJhc2UiXSwianRpIjoiMWRiOTIxYjUtNGZjMS00NWZkLThmNDAtZTA0NTBkZTMyODEyIiwiY2xpZW50X2lkIjoiYzEifQ.-u2Zzn9iWtb15SSijx3kccxBJyJr6_56ktkG3gVrajM"
                },
                success(resource) {
                  console.log(resource);
                },
                error(err) {
                  console.log(err);
                }
    
            })
            
           
          })

       //原生 window.onload
    =function() { var xmlHttp; if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); }else { xmlHttp = window.ActiveXObject("Microsoft.XMLHTTP"); } //数据组装 var data = {"Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdLCJ1c2VyX25hbWUiOiJ7XCJlbWFpbFwiOlwiMjExOTI5OTUzMUBxcS5jb21cIixcImZ1bGxuYW1lXCI6XCLlsI_luoRcIixcImlkXCI6MyxcInBhc3N3b3JkXCI6XCIkMmEkMTAkc1o4d0d4NHkvcG1CM1g4QkFGZWxTLmpqR2M2TE8weDluMWFzR1cvWEVPT2VQMGF1dmFkSnFcIixcInVzZXJuYW1lXCI6XCIxODQ3NjMwNTY0MFwifSIsInNjb3BlIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiLCJST0xFX0FQSSJdLCJleHAiOjE2MjM4Mzc4MDUsImF1dGhvcml0aWVzIjpbImJhc2UiXSwianRpIjoiMWRiOTIxYjUtNGZjMS00NWZkLThmNDAtZTA0NTBkZTMyODEyIiwiY2xpZW50X2lkIjoiYzEifQ.-u2Zzn9iWtb15SSijx3kccxBJyJr6_56ktkG3gVrajM"} //发送请求 xmlHttp.open("get","http://localhost/user/test",true); xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdLCJ1c2VyX25hbWUiOiJ7XCJlbWFpbFwiOlwiMjExOTI5OTUzMUBxcS5jb21cIixcImZ1bGxuYW1lXCI6XCLlsI_luoRcIixcImlkXCI6MyxcInBhc3N3b3JkXCI6XCIkMmEkMTAkc1o4d0d4NHkvcG1CM1g4QkFGZWxTLmpqR2M2TE8weDluMWFzR1cvWEVPT2VQMGF1dmFkSnFcIixcInVzZXJuYW1lXCI6XCIxODQ3NjMwNTY0MFwifSIsInNjb3BlIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiLCJST0xFX0FQSSJdLCJleHAiOjE2MjM4Mzc4MDUsImF1dGhvcml0aWVzIjpbImJhc2UiXSwianRpIjoiMWRiOTIxYjUtNGZjMS00NWZkLThmNDAtZTA0NTBkZTMyODEyIiwiY2xpZW50X2lkIjoiYzEifQ.-u2Zzn9iWtb15SSijx3kccxBJyJr6_56ktkG3gVrajM"); //发送数据 xmlHttp.send(data); //事件监听 xmlHttp.onreadystatechange=function () { //状态信息 if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { var result = xmlHttp.responseText; console.log(result); } }
       }

    演示的是相同的请求

  • 相关阅读:
    结对项目 sport club(一)
    结对项目 sport club(三)
    结对项目 sport club(二)
    博客作业
    学生信息管理系统APP需求分析
    随机生成四则运算
    软件介绍
    利用纯css写三角形,弧度箭头,吃豆人,气泡。放大镜,标签的源码
    js中的数据类型隐式转换的三种情况
    javascript基础入门之js中的结构分支与循环语句
  • 原文地址:https://www.cnblogs.com/zjazn/p/14890300.html
Copyright © 2020-2023  润新知