此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

XMLHttpRequest.responseURL

基线 广泛可用

自 2016年8月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

只读属性 XMLHttpRequest.responseURL 返回响应的序列化 URL,如果 URL 为空则返回空字符串。如果 URL 有锚点,则位于 URL # 后面的内容会被删除。如果 URL 有重定向,responseURL 的值会是经过多次重定向后的最终 URL。

实例

js
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://example.com/test", true);
xhr.onload = function () {
  console.log(xhr.responseURL); // http://example.com/test
};
xhr.send(null);

规范

规范
XMLHttpRequest
# the-responseurl-attribute

浏览器兼容性