get authorization header javascript in my page
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="tryit();">PDF</button>
<script>
function tryit() {
var win = window.open('_blank');
downloadFile('/pdf', function(blob) {
var url = URL.createObjectURL(blob);
win.location = url;
});
}
function downloadFile(url, success) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
xhr.responseType = "blob";
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (success) success(xhr.response);
}
};
xhr.send(null);
}
</script>
</body>
</html>
Also in JavaScript:
- jquery on form submit call function
- js array into object
- ngmodel onchange
- filter array objects javascript
- reactjs cloudflare
- Switch Button in react
- node js sendgrid
- _.get alternative
- javascript key pressed enter
- javascript number format
- javascript capitalize
- javascript while loop
- reactjs web3 components
- discord bot v12 reaction remove code
- snackbar in react
- javascript string keys
- json-server localhost
- jquery each
- pub js npm
- javascript reverse array without modifying
- javascript get clock time in auto counter up
- express img folder
- Unexpected end of JSON input while parsing near
- how many threads does node js use