showing results for - "get authorization header javascript in my page"
Tim
08 Mar 2016
1<!DOCTYPE html>
2<html>
3<head>
4</head>
5<body>
6<button onclick="tryit();">PDF</button>
7<script>
8    function tryit() {
9        var win = window.open('_blank');
10        downloadFile('/pdf', function(blob) {
11            var url = URL.createObjectURL(blob);
12            win.location = url;
13        });
14    }
15    function downloadFile(url, success) {
16        var xhr = new XMLHttpRequest();
17        xhr.open('GET', url, true);
18        xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
19        xhr.responseType = "blob";
20        xhr.onreadystatechange = function() {
21            if (xhr.readyState == 4) {
22                if (success) success(xhr.response);
23            }
24        };
25        xhr.send(null);
26    }
27
28</script>
29</body>
30</html>
queries leading to this page
how to check authorization header in javascriptjs headers with authorizationset authorization header javascript for responseget authorization header from request jsset authorization header javascriptjavascript header authorizationjavascript request header authorizationjavascript authorization headerjavascript read authorization headerrequest headers authorization javascriptjs set header authorizationhow to check authorization header is there or not in url on javascripthow to add authorization header to http request in javascriptjavascript http request authorization headermake a js request with authorization headerjavascript get authorization header from responsejavascript set header authorizationhow to set request authorization header javascriptjavascript send authorization code in headershow to set authorization header jsjavascript get authorization headerjs set authorization headerhow to get authorization from headers in javascripthow to add authorization header html with javascriptget authorization header javascript in my pagejavascript get request with authorization headerhow to set header automatically after authorization javascriptsetup authorization header jshttp authorization header javascriptheader retrieve authorization jsjs basic auth header set authorization header in javascripthow to get authorization header in javascripthow to set authorization header in javascriptset http header authorization jssetting authorization header jsjavascript print out authorization headersget request with authorization header jsjs get authorization headerheaders get 28 authorization 29 jshow to send authorization header in get request jsjavascript http authorization headerget headers authorization jsauthorization header javascriptjs authorization headerget authorization token from header javascriptheader authorization html jsauthorization header javascroiptauthorization header validation javascriptjavascript set authorization headerhow to pass authorization header in url javascriptjavascript request header authorization set valueset authorization header and url in javascriptget authorization header javascript in my page