javascript - 如何在 XMLHttpRequest 中获取响应 url?

标签 javascript ajax xmlhttprequest response

有一个页面(url),我通过 XMLHttpRequest 请求它,但我没有从请求的 url 得到响应,它正在将请求定向到另一个页面,

请求---> page.php
从 > directedpage.php

获得响应

问题是我怎样才能得到响应 url? (示例中的 directedpage.php)

最佳答案

最终 URL(经过所有重定向后)在 responseURL attribute 中可用。 XMLHttpRequest 实例的。 此功能是新功能,仅在 2014 年 9 月的 Firefox 32 稳定版中受支持 [ref] 和 Chrome 37.0.2031.0 2014 年 8 月稳定 [ref] (可能还有 Opera 24)。 responseURL(目前)在 IE 11 或 Safari 7 及更早的浏览器中不受支持。对于这些浏览器,之前的答案仍然成立:

XMLHttpRequest automatically follows redirects, without saving the served URLs in a property. The Location header can neither be retrieved through the .getResponseHeader().

引用资料:

关于javascript - 如何在 XMLHttpRequest 中获取响应 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8056277/

相关文章:

javascript - jquery中不同行的索引类

javascript - 只有 JQuery 可以与 FormData 一起使用吗?

python - Flask:通过 ajax 返回按钮的 id

PHP Ajax XMLHttpRequest popen 实时进度

php - 取消 XHR 请求

javascript - 你如何使用pdf.js获取客户端存储的pdf的文本内容?

javascript - "更改为双引号

javascript - 链接到另一个页面的特定 div;在该页面上只能链接到该 div

javascript - 将 aspx 加载到 div : wrong path

jquery - 使用ajax发送JSON到action,参数为null(返回内部服务器错误500)