我正在尝试使用JQuery在Ajax中添加标头请求.
以下是代码: -
$.ajax({ type: "POST", contentType: "application/json", url: "http://localhost:8080/core-service/services/v1.0/patients/registerPatients", data: JSON.stringify(patientDTO), //crossDomain : true, dataType: 'json', headers: {"X-AUTH-TOKEN" : tokken}, success: function(patientDTO) { console.log("SUCCESS: ", patientDTO); /* location.href = "fieldagentHRA.html";*/ if (typeof(Storage) !== "undefined") { localStorage.setItem("patUrn", patientDTO.data); location.href="fieldagentHRA.html"; } }, error: function(e) { console.log("ERROR: ", e); display(e); }, done: function(e) { enableRegisterButton(true); } });
然后我使用了Requestly(Requestly是chrome + firefox插件,我们可以手动为请求添加标头).
手动添加标题后: -
在两个图片请求标题中,x-auth-token存在于"ACCESS-CONTROL-REQUEST-HEADERS"中,但是"X-AUTH-TOKEN"标题连同标题值存在于第二pic中,而第二pic中不存在第一pic.
所以我的问题是如何使用JQuery在Ajax中添加请求头?