简体   繁体   English

如何使用javascript访问AJAX未发送的HTTP响应标题?

[英]How to access the headers a HTTP response that you didn't send by AJAX using javascript?

I currently have a login page set up where it sends a HTTP post request to the server and then in a response message it redirects me to another page on the server. 我目前设置了一个登录页面,它向服务器发送HTTP post请求,然后在响应消息中将其重定向到服务器上的另一个页面。 On that page I want to access the location header which contains a value that I need to perform future work with my server. 在该页面上,我想访问位置标题,其中包含我将在以后与我的服务器一起工作所需的值。 Is there anyway to read that location header from the response so that I can get the value? 无论如何都要从响应中读取位置标题,以便我可以获取值?

I know that you can access headers if you sent an ajax request by using the XMLHttpRequest object in the callback! 我知道如果您通过回调中的XMLHttpRequest对象发送了ajax请求,则可以访问标头! But I am not using ajax so I cannot do that? 但我不是在使用ajax,所以我不能这样做?

Thanks so much! 非常感谢!

No, that information is not available. 不,该信息不可用。 For a complete explanation, see Accessing the web page's HTTP Headers in JavaScript . 有关完整说明,请参阅在JavaScript中访问网页的HTTP标头

Your best bet would be to have the server put the information somewhere on the new page where you can retrieve it, eg a hidden field. 您最好的选择是让服务器将信息放在新页面的某个位置,您可以在其中检索它,例如隐藏字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM