IE错过标题-角$ http [英] IE misses Headers - angular $http
问题描述
我正在尝试使用angularjs $ http从远程服务器(inaturalist.org)获取结果.服务器使用标头来指定分页信息(总条目,页面等).
I`m trying to fetch results from remote server (inaturalist.org) using angularjs $http. The server use headers to specify Paging information (total entries, page, etc).
我的问题是使用IE(Edge,经过IE11测试)时,我看不到所有标题.
My problem is when using IE (Edge, IE11 tested) I cant see all the headers.
$http({
method : 'GET',
url : 'https://www.inaturalist.org/observations.json?page=1&per_page=30'})
.success(function (data, status, headers) {
scope.headers = headers();
});
});
请参见 https://jsbin.com/rohoda/edit?js,output
有什么想法吗?
推荐答案
这是Internet Explorer对XMLHttpRequest对象的实现中的错误.由于您是在进行跨域请求,因此适用CORS规则.这是一个GET请求,因此没有必要进行飞行前OPTIONS请求.服务器正确返回以下响应头:
This is a bug in Internet Explorer's implementation of the XMLHttpRequest object. Since you are making a cross domain request CORS rules apply. It is a GET request so it is not necessary to make a pre-flight OPTIONS request. The server correctly returns the following response header:
Access-Control-Expose-Headers: X-Per-Page, X-Total-Entries
,但是您无法使用getResponseHeader()
方法(此header
变量在成功回调中代表的意思).
and yet you cannot access the X-Total-Entries
response header using the getResponseHeader()
method (which is what this header
variable represents in the success callback).
唯一能够完全正确地实现此Access-Control-Expose-Headers
CORS标头的浏览器是Google Chrome.
The only browser that fully and correctly implements this Access-Control-Expose-Headers
CORS header is Google Chrome.
您可能会找到 following article
有用,尤其是底部的Access-Control-Expose-Headers problem
部分:
所有浏览器(谷歌浏览器除外)的bug getRequestHeader() 实现,因此客户端甚至可能无法访问标头 设置Access-Control-Expose-Headers标头后.在我的例子中 ETag标头只能在Google Chrome浏览器中访问. Safari返回 仅简单的响应标头,而Firefox不返回ANY 响应标头.
All browsers (except Google Chrome) have buggy getRequestHeader() implementations, so the headers may not be accessible to clients even after you set the Access-Control-Expose-Headers header. In my example, ETag header accessible only in Google Chrome browser. Safari return only simple response headers, while Firefox doesn't return ANY response headers.
恐怕这里唯一的解决方法是在您的域上设置代理脚本,该脚本将充当您的域和远程域之间的桥梁.然后,向您自己的域发出AJAX请求,从而避免使用CORS.
I am afraid that the only workaround here is to setup a proxy script on your domain that will act as a bridge between your domain and the remote domain. Then make the AJAX request to your own domain to avoid the need of using CORS.
这篇关于IE错过标题-角$ http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!