简体   繁体   English

JavaScript/jQuery:无法获得“WWW-Authenticate”响应头

[英]JavaScript/jQuery: Can´t get "WWW-Authenticate" response header

I have following jQuery-code:我有以下 jQuery 代码:

$.ajax({
  type: "GET",
  url: url,
  complete: function( data ){
    console.info( data.getResponseHeader("WWW-Authenticate") );
  }
});

Which will return null.这将返回空值。 In Firebug I can see, that the header "WWW-Authenticate" is sent by the server.在 Firebug 中,我可以看到,标头“WWW-Authenticate”是由服务器发送的。

Is there any way to get the header?有没有办法得到标题? If I can see it in Firebug, then it should be possible to get it in jQuery.如果我可以在 Firebug 中看到它,那么应该可以在 jQuery 中获得它。

I already tried stuff like:我已经尝试过类似的东西:

beforeSend: function(xhr){
    xhr.setRequestHeader( "withCredentials", true );
    xhr.setRequestHeader( "Access-Control-Expose-Headers", "WWW-Authenticate" );
    xhr.setRequestHeader( "Access-Control-Allow-Headers", "WWW-Authenticate" );
  }

If I try:如果我尝试:

data.getAllResponseHeaders()

// Returns:
Cache-Control: private
Content-Type: text/html

But in Firebug, I see WAY more headers... a lot more.但是在 Firebug 中,我看到了更多的标题......更多。

Thank you very much!非常感谢!

Thank you very much!非常感谢!

If you are using CORS requests it's normal to see all other header data in firebug, but in your xHR object you will see just few of them (content type, last-modified, language, expires, pragma and cache control)如果您使用 CORS 请求,在 firebug 中看到所有其他标头数据是正常的,但在您的 xHR 对象中,您只会看到其中的一小部分(内容类型、上次修改时间、语言、过期、编译指示和缓存控制)

You may play around and try to add this to your server response (if you have access to it) by sending Access-Control-Expose-Headers take a look here for more details.您可以尝试通过发送Access-Control-Expose-Headers来尝试将其添加到您的服务器响应中(如果您可以访问它),请查看此处了解更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM