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);
    }
})

 

posted @ 2019-01-23 15:26  無玑小姐  阅读(1929)  评论(0编辑  收藏  举报