Javascript 如何在不使用 JS 发出新请求的情况下读取当前标头?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12258705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I read the current headers without making a new request with JS?
提问by fj123x
Possible Duplicate:
Accessing HTTP Headers in Javascript?
The only way what i know to read with javascript the current headers is:
我知道使用 javascript 读取当前标题的唯一方法是:
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
But i don't want make a new request, i want read the current headers.
但我不想提出新的请求,我想阅读当前的标题。
Is this posible? Thanks!
这可能吗?谢谢!
回答by WTK
It's not possible to access page headers via Javascript, without sending ajax request.
如果不发送 ajax 请求,则无法通过 Javascript 访问页眉。