[英]Access Specific Header from JQuery Ajax Response
I'm performing a POST Method using JQuery 我正在使用JQuery执行POST方法
var params = JSON.stringify({ UserName: usr, Password: pwd });
var temp = $.ajax({
method: 'POST',
contentType: 'application/json',
url: 'some-url',
data: params,
dataType: 'json',
complete: function (data, textStatus, request) {
var ResponseCode = data.responseJSON.ResponseCode;
var ResponseMessage = data.responseJSON.ResponseMessage;
var TokenKey = data.responseJSON.TokenKey;
var UserName = data.responseJSON.UserName;
var type = data.responseJSON.Type;
if (ResponseCode == 100 && type == 1) {
window.open("page2.html", "_self");
}
else if (ResponseCode == 100 && type == 0) {
window.open("page1.html", "_self");
}
else if (ResponseCode != 100) {
alert(temp.getAllResponseHeaders);
}
},
error: function (data) {
alert("error")
}
});
now i can successfully find all the required data in the response body but there is some a specific header which i wish to put into a variable 现在我可以在响应正文中成功找到所有必需的数据,但是我希望将某些特定的标头放入变量中
i tried implementing the following lines withing the COMPLETE sector 我尝试对COMPLETE部门实施以下几行
var h = request.getHeader("Authorization-Token");
var h = request.getAllHeaders("Authorization-Token");
yet i'm always getting null or undefined Any help or suggestion is Much appreciated 但是我总是得到null或undefined任何帮助或建议,我们深表感谢
在服务器上,您需要将此标头添加到响应中:
Access-Control-Expose-Headers: Authorization-Token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.