如何在AJAX中获取Response标头 [英] How to get Response headers in AJAX
本文介绍了如何在AJAX中获取Response标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码进行AJAX调用
I am using the following code for an AJAX call
$.ajax({
type: "POST",
url: "http://******/cxf/view/*****",
data: {*****},
headers: {*****},
success: function (dt, status, request) {
console.log(request.getAllResponseHeaders());
},
error: function (jqXHR, status) {
}
});
这仅打印内容类型.在开发人员控制台中,我可以在响应中看到标头的数量.我如何在AJAX中获得这些标头
This is printing only content-type. In the developer console i can see number of headers in the response. How can i get those headers in AJAX
推荐答案
似乎没有问题.我尝试过并使其起作用.
It's seems no problem. I tried and got it works.
使用 JSONPlaceholder ,这是我的代码
$.ajax({
url: root + '/posts/1',
headers: {'test': 'test'},
method: 'GET'
}).then(function(data, status, xhr) {
console.log(xhr.getAllResponseHeaders());
});
结果是
Pragma: no-cache
Date: Wed, 23 Dec 2015 06:36:57 GMT
Via: 1.1 vegur
X-Content-Type-Options: nosniff
Server: Cowboy
X-Powered-By: Express
Vary: Origin
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
Access-Control-Allow-Credentials: true
Content-Length: 292
Etag: W/"124-yv65LoT2uMHrpn06wNpAcQ"
Expires: -1
这篇关于如何在AJAX中获取Response标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文