Skip to content

Commit b94a93d

Browse files
committed
Merge branch 'awalGarg-patch-2'
2 parents c8816d1 + b8c8821 commit b94a93d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

snippets/showheaders/showheaders.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
(function() {
66

77
var request=new XMLHttpRequest();
8-
request.open('HEAD',window.location,false);
9-
request.send(null);
10-
11-
var headers = request.getAllResponseHeaders();
12-
var tab = headers.split("\n").map(function(h) {
13-
return { "Key": h.split(": ")[0], "Value": h.split(": ")[1] }
14-
}).filter(function(h) { return h.Value !== undefined; });
8+
request.open('HEAD',window.location,true);
9+
10+
request.onload = request.onerror = function () {
11+
var headers = request.getAllResponseHeaders();
12+
var tab = headers.split("\n").map(function(h) {
13+
return { "Key": h.split(": ")[0], "Value": h.split(": ")[1] }
14+
}).filter(function(h) { return h.Value !== undefined; });
1515

16-
console.group("Request Headers");
17-
console.log(headers);
18-
console.table(tab);
19-
console.groupEnd("Request Headers");
16+
console.group("Request Headers");
17+
console.log(headers);
18+
console.table(tab);
19+
console.groupEnd("Request Headers");
20+
};
21+
22+
request.send(null);
2023

2124
})();

0 commit comments

Comments
 (0)