CORS / xhr.getRequestHeaders [英] CORS / xhr.getRequestHeaders

查看:599
本文介绍了CORS / xhr.getRequestHeaders的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我试图使用CORS( http://www.w3.org/TR/2009/WD-cors-20090317/#access-control-allow-methods-header ),当我尝试从XMLHTTPRequest读取响应头,我只收到内容类型。没有其他很标准的标头通过,我不知道如何让这个工作。

I am trying to use CORS (http://www.w3.org/TR/2009/WD-cors-20090317/#access-control-allow-methods-header) for an application on Safari, and when I try to read the response headers from the XMLHTTPRequest, I only receive the Content-Type. None of the other quite standard headers gets through, and I cannot figure out how to get this to work.

任何人都会发生,知道如何解决这个问题?这是一个WebKit错误吗?

Anyone would happen to know how to fix this issue? Could this be a WebKit bug?

编辑

使用nGinx:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers Cache-Control,Pragma,Date;
add_header Access-Control-Allow-Methods GET,POST;


推荐答案

为了让标题暴露给JS,需要设置 访问控制 -

In order for headers to be exposes to JS, you need to set the Access-Control-Expose-Headers header to a comma-separated list of headers you want to expose.

不幸的是,这个列表头部支持不足。 Mozilla只在Firefox 4中实现它,Webkit目前仍然不实现它。我不知道IE8及以上(谷歌没有打开任何有用的,我没有他们在测试自己)。

Unfortunately, this header is poorly supported. Mozilla only implemented it in Firefox 4, Webkit as of this moment still does not implement it. I am not sure about IE8 and above (google didn't turn up anything useful, and I don't have them around to test with myself).

(另见例如 XMLHttpRequest的getResponseHeader()的限制?

这篇关于CORS / xhr.getRequestHeaders的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆