Skip to content

Instantly share code, notes, and snippets.

@nealjin
Created December 26, 2014 07:08
Show Gist options
  • Select an option

  • Save nealjin/9b84a1734d0593a92faa to your computer and use it in GitHub Desktop.

Select an option

Save nealjin/9b84a1734d0593a92faa to your computer and use it in GitHub Desktop.
js获取Response Headhers信息
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