Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active July 5, 2017 06:33
Show Gist options
  • Save xgqfrms-GitHub/68af127cb3ec33587ee5bffe9810fb1b to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/68af127cb3ec33587ee5bffe9810fb1b to your computer and use it in GitHub Desktop.
AJAX & XMLHttpRequest & Fetch & Worker & jquery ajax
@xgqfrms-GitHub
Copy link
Author

let myImage = document.querySelector('img');

let myHeaders = new Headers();
myHeaders.append('Content-Type', 'image/png');

const myInit = {
    method: 'GET',
    headers: myHeaders,
    mode: 'cors',
    cache: 'default'
};

let myRequest = new Request('https://cdn.xgqfrms.xyz/logo/icon.png');

fetch(myRequest, myInit)
.then(function(response) {
    return response.blob();
})
.then(function(blob) {
    var objectURL = URL.createObjectURL(blob);
    myImage.src = objectURL;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment