【问题标题】:JavaScript/jQuery: Can´t get "WWW-Authenticate" response headerJavaScript/jQuery:无法获得“WWW-Authenticate”响应标头
【发布时间】:2015-11-12 13:36:07
【问题描述】:

我有以下 jQuery 代码:

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

这将返回 null。在 Firebug 中,我可以看到,标头“WWW-Authenticate”是由服务器发送的。

有什么方法可以获取标题吗?如果我可以在 Firebug 中看到它,那么应该可以在 jQuery 中得到它。

我已经尝试过类似的东西:

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

如果我尝试:

data.getAllResponseHeaders()

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

但在 Firebug 中,我看到的标题要多得多……更多。

非常感谢!

非常感谢!

【问题讨论】:

    标签: javascript jquery http-headers httpresponse digest-authentication


    【解决方案1】:

    如果您使用 CORS 请求,在 firebug 中看到所有其他标头数据是正常的,但在您的 xHR 对象中您只会看到其中的几个(内容类型、上次修改时间、语言、过期、编译指示和缓存控制)

    您可以尝试通过发送 Access-Control-Expose-Headers 将其添加到您的服务器响应中(如果您有权访问它),请查看here 了解更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 2016-06-02
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多