問題描述
是否可以在發送 XMLHttpRequest-s 時阻止瀏覽器跟隨重定向(即取回重定向狀態碼并自己處理)?
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 對象的 W3C 標準(已添加重點):
Not according to the W3C standard for the XMLHttpRequest object (emphasis added):
如果響應是 HTTP 重定向:
If the response is an HTTP redirect:
如果 Location 標頭傳達的 URL 的來源是同一個來源與 XMLHttpRequest 來源和重定向不違反無限循環預防措施,透明在觀察的同時遵循重定向同源請求事件規則.
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.
他們考慮在未來發布:
本規范不包括以下功能正在考慮用于未來版本本規范:
This specification does not include the following features which are being considered for a future version of this specification:
- 禁用以下重定向的屬性;
但 最新 規范不再提及這一點.
but the latest specification no longer mentions this.
這篇關于防止 Xmlhttprequest 的重定向的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!