ajax設置自定義請求頭
阿新 • • 發佈:2019-01-23
eal class xhr inter api cti ucc span spa
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); } })
ajax設置自定義請求頭