简体   繁体   中英

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. 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! But I am not using ajax so I cannot do that?

Thanks so much!

No, that information is not available. For a complete explanation, see Accessing the web page's HTTP Headers in JavaScript .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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