如何在 XMLHttpRequest 中获取响应 url?
有一个页面(url),我通过 XMLHttpRequest 请求它,但我没有从请求的 url 得到响应,它正在将请求定向到另一个页面,
There is a page (url), I request it by XMLHttpRequest, but I'm not getting response from requested url, It's directing request to another page,
请求---> page.php
从 > directedpage.php
问题是如何获得响应网址?(以directedpage.php为例)
and the question is how can I get response url? (directedpage.php in example)
推荐答案
在 XMLHttpRequest 实例的 responseurl-attribute">responseURL
属性.此功能是新功能,仅在 2014 年 9 月稳定的 Firefox 32 [ref] 和 Chrome 中受支持37.0.2031.0 2014 年 8 月稳定[ref](可能还有 Opera 24).responseURL
在 IE 11 或 Safari 7 及更早版本的浏览器中(尚)不受支持.对于这些浏览器,之前的答案依然成立:
The final URL (after following all redirects) is available in the responseURL
attribute of a XMLHttpRequest
instance.
This feature is new and only supported in Firefox 32 stable in September 2014 [ref] and Chrome 37.0.2031.0 stable in August 2014 [ref] (and probably also Opera 24). responseURL
is not (yet) supported in IE 11 or Safari 7 and older browsers. For these browsers, the previous answer is still true:
XMLHttpRequest
自动跟随重定向,而不将提供的 URL 保存在属性中.Location
标头既不能通过 .getResponseHeader()
检索.
XMLHttpRequest
automatically follows redirects, without saving the served URLs in a property. TheLocation
header can neither be retrieved through the.getResponseHeader()
.
参考资料:
- https://groups.google.com/a/chromium.org/d/msg/blink-dev/AU6pAiYZ8J4/ec5jgoEDsF0J
- https://bugzilla.mozilla.org/show_bug.cgi?id=998076李>
相关文章