How to get response url in XMLHttpRequest?

拟墨画扇 提交于 2019-12-17 03:43:08

问题


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,

requesting --- > page.php
getting reponse from > directedpage.php

and the question is how can I get response url? (directedpage.php in example)


回答1:


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 automatically follows redirects, without saving the served URLs in a property. The Location header can neither be retrieved through the .getResponseHeader().

References:

  • https://groups.google.com/a/chromium.org/d/msg/blink-dev/AU6pAiYZ8J4/ec5jgoEDsF0J
  • https://bugzilla.mozilla.org/show_bug.cgi?id=998076


来源:https://stackoverflow.com/questions/8056277/how-to-get-response-url-in-xmlhttprequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!