昨天項目中,由於要請求token驗證,后台給出的方案是采用請求頭返回token數據,給出的API文檔是這樣的

由於之前一直都是采用請求體發送請求,服務器在應答體李返回數據。和這個不一樣;
采用jq的$.ajax()函數發送請求,代碼如下
$.ajax({ type: 'POST', url: '/token', headers:{"appId":appId,"appKey":appKey,"Content-Type":"text/plain;charset=UTF-8"}, data:"{}", success: function(data, status, xhr){ console.log(xhr); }, error: function(xhr, type){ window.location.reload(); }
這樣寫正確,能夠正確發送請求,也能正常收到response headers:

使用jq的
getAllResponseHeaders()能得到所有response headers,取到的值是str類型;
使用
getResponseHeader('token')能得到token的值;
