如何在 XMLHttpRequest 中获取响应 url? [英] How to get response url in XMLHttpRequest?

查看:30
本文介绍了如何在 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)

推荐答案

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() 检索.

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

参考资料:

这篇关于如何在 XMLHttpRequest 中获取响应 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆