--- title: XMLHttpRequest.responseURL slug: Web/API/XMLHttpRequest/responseURL tags: - XMLHttpRequest.responseURL translation_of: Web/API/XMLHttpRequest/responseURL ---
{{APIRef('XMLHttpRequest')}}
只读属性XMLHttpRequest.responseURL返回响应的序列化URL,如果URL为空则返回空字符串。如果URL有锚点,则位于URL # 后面的内容会被删除。如果URL有重定向, responseURL 的值会是经过多次重定向后的最终 URL 。
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);
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('XMLHttpRequest', '#the-responseurl-attribute')}} | {{Spec2('XMLHttpRequest')}} | WHATWG living standard |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | {{CompatChrome(37.0)}} | {{CompatGeckoDesktop("32.0")}} | {{CompatNo}} | {{CompatOpera("24")}} | {{CompatSafari(8.0)}} |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |