Created
December 26, 2014 07:08
-
-
Save nealjin/9b84a1734d0593a92faa to your computer and use it in GitHub Desktop.
js获取Response Headhers信息
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fetchSimilarHeaders (callback) { | |
| var request = new XMLHttpRequest(); | |
| request.onreadystatechange = function () { | |
| if (request.readyState === 4) { | |
| // | |
| // The following headers may often be similar | |
| // to those of the original page request... | |
| // | |
| if (callback && typeof callback === 'function') { | |
| callback(request.getAllResponseHeaders()); | |
| } | |
| } | |
| }; | |
| // | |
| // Re-request the same page (document.location) | |
| // We hope to get the same or similar response headers to those which | |
| // came with the current page, but we have no guarantee. | |
| // Since we are only after the headers, a HEAD request may be sufficient. | |
| // | |
| request.open('HEAD', document.location, true); | |
| request.send(null); | |
| } | |
| fetchSimilarHeaders(function(data) { | |
| console.log(data); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment