How to get response url in XMLHttpRequest?(如何在 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() 检索.
XMLHttpRequestautomatically follows redirects, without saving the served URLs in a property. TheLocationheader 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李>
这篇关于如何在 XMLHttpRequest 中获取响应 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 XMLHttpRequest 中获取响应 url?
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
