ajax设置自定义请求头


1,

$.ajax({
    url:apiUrl,
    type:"get",
    timeout : 5000, //超时时间设置,单位毫秒
    dataType: "json",
    beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Bearer "+obj.data); xhr.setRequestHeader("Accept", "application/json"); },
    success:function(obj){
        dealApiInterfaceResult(resourceId, obj);
    }
})

2,

$.ajax({
    url:apiUrl,
    type:"get",
    timeout : 5000, //超时时间设置,单位毫秒
    dataType: "json",
    headers: { 'Authorization':"Bearer "+obj.data, 'Accept':"application/json" },
    success:function(obj){
        dealApiInterfaceResult(resourceId, obj);
    }
})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM