如何在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