使用: xhr.responseURL; 

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

 

注意:

1. xhr.responseURL和xhr.open()中的URL可能是不一样的, 因为服务器也可能发生跳转, 前者返回的是最后实际返回数据的URL;

2. 如果原始请求URL包含锚点(#), 则该属性会将锚点抽离;

相关文章:

  • 2022-12-23
  • 2021-06-29
  • 2021-11-07
  • 2021-08-05
  • 2021-12-05
  • 2022-01-05
  • 2021-07-26
猜你喜欢
  • 2022-02-06
  • 2021-08-03
  • 2021-04-13
  • 2021-10-28
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案