$.ajax HEAD Request Just To Get Response Headers Of Same page

Posted at


$.ajax(document.location.href,{type:'HEAD'}).done(function(data,status,xhr){
var result = "<table><tr><th>Header Name</th><th>Header Value</th></tr>" + "<tr><td>" + xhr.getAllResponseHeaders()
.replace("\","") //normalize line-breaks
.replace(/\
$/,"") //remove extra line-break at the end
.split("\
").join("</td></tr>\
<tr><td>") //table rows
.split(": ").join("</td><td>") //table columns
+ "</td></tr></table>"


console.log(result);

});


it works well if your headers values do not include any :{SPACE}