問(wèn)題描述
有一個(gè)頁(yè)面(url),我通過(guò) XMLHttpRequest 請(qǐng)求它,但我沒(méi)有從請(qǐng)求的 url 得到響應(yīng),它正在將請(qǐng)求定向到另一個(gè)頁(yè)面,
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,
請(qǐng)求---> page.php
從 > directedpage.php
問(wèn)題是如何獲得響應(yīng)網(wǎng)址?(以directedpage.php為例)
and the question is how can I get response url? (directedpage.php in example)
推薦答案
在 XMLHttpRequest 實(shí)例的 responseurl-attribute">responseURL
屬性.此功能是新功能,僅在 2014 年 9 月穩(wěn)定的 Firefox 32 [ref] 和 Chrome 中受支持37.0.2031.0 2014 年 8 月穩(wěn)定[ref](可能還有 Opera 24).responseURL
在 IE 11 或 Safari 7 及更早版本的瀏覽器中(尚)不受支持.對(duì)于這些瀏覽器,之前的答案依然成立:
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
自動(dòng)跟隨重定向,而不將提供的 URL 保存在屬性中.Location
標(biāo)頭既不能通過(guò) .getResponseHeader()
檢索.
XMLHttpRequest
automatically follows redirects, without saving the served URLs in a property. TheLocation
header 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李>
這篇關(guān)于如何在 XMLHttpRequest 中獲取響應(yīng) url?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!