且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从跨域 Ajax 请求访问 Content-Length 标头?

更新时间:2022-05-05 22:54:15

我发现所有浏览器对 CORS 响应标头的支持都存在问题.在 Chrome/Safari 中,我只在 getAllResponseHeaders() 的结果中看到简单的响应标头 (http://www.w3.org/TR/cors/#terminology),即使是Access-Control-Expose-Headers"标头在响应中设置.在 Firefox 3.6.13 中, getAllResponseHeaders() 不返回任何内容(甚至不返回简单的响应标头).作为一种解决方法,我想您可以重载一个简单的响应标头以包含内容长度,但这可能会导致其他问题,并且仍然无法修复 Firefox.

I've found CORS response header support in all browsers to be buggy. In Chrome/Safari, I only see simple response headers (http://www.w3.org/TR/cors/#terminology) in the result of getAllResponseHeaders(), even when the "Access-Control-Expose-Headers" header is set in the response. And in Firefox 3.6.13, getAllResponseHeaders() doesn't return anything (not even simple response headers). As a workaround, I suppose you could overload one of the simple response headers to include the content-length, but that may cause other issues, and still wouldn't fix Firefox.