Skip to content

Instantly share code, notes, and snippets.

@TheGreatRambler
Created March 4, 2018 21:48
Show Gist options
  • Save TheGreatRambler/6b0db0af9c52acc406689f587b0b4bc8 to your computer and use it in GitHub Desktop.
Save TheGreatRambler/6b0db0af9c52acc406689f587b0b4bc8 to your computer and use it in GitHub Desktop.
Get headers of file from ajax request
function returnheaders(ajaxrequest) {
var headers = ajaxrequest.getAllResponseHeaders();
var arrofheaders = headers.trim().split(/[\r\n]+/);
var mapofheaders = {};
arrofheaders.forEach(function (line) {
var parts = line.split(': ');
var header = parts.shift();
var value = parts.join(': ');
mapofheaders[header] = value;
});
return mapofheaders;
}
// Usage
$.ajax({
src: "test.txt"
}).done(function(data, textStatus, jqXHR) {
var headers = returnheaders(jqXHR);
console.log(headers);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment