問(wèn)題描述
是否可以在發(fā)送 XMLHttpRequest-s 時(shí)阻止瀏覽器跟隨重定向(即取回重定向狀態(tài)碼并自己處理)?
Is it possible to prevent the browser from following redirects when sending XMLHttpRequest-s (i.e. to get the redirect status code back and handle it myself)?
推薦答案
不按照XMLHttpRequest 對(duì)象的 W3C 標(biāo)準(zhǔn)(已添加重點(diǎn)):
Not according to the W3C standard for the XMLHttpRequest object (emphasis added):
如果響應(yīng)是 HTTP 重定向:
If the response is an HTTP redirect:
如果 Location 標(biāo)頭傳達(dá)的 URL 的來(lái)源是同一個(gè)來(lái)源與 XMLHttpRequest 來(lái)源和重定向不違反無(wú)限循環(huán)預(yù)防措施,透明在觀察的同時(shí)遵循重定向同源請(qǐng)求事件規(guī)則.
If the origin of the URL conveyed by the Location header is same origin with the XMLHttpRequest origin and the redirect does not violate infinite loop precautions, transparently follow the redirect while observing the same-origin request event rules.
他們考慮在未來(lái)發(fā)布:
本規(guī)范不包括以下功能正在考慮用于未來(lái)版本本規(guī)范:
This specification does not include the following features which are being considered for a future version of this specification:
- 禁用以下重定向的屬性;
但 最新 規(guī)范不再提及這一點(diǎn).
but the latest specification no longer mentions this.
這篇關(guān)于防止 Xmlhttprequest 的重定向的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!