The base64 for the image prints to the console, but I cannot figure out how to assign this value into a variable. I have been looking around for a while now and cannot seem to find a simply, concise answer. I am really new to JS.
function toDataURL(url, callback) {
let xhr = new XMLHttpRequest();
xhr.onload = function () {
let reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
};
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
//return xhr.responseText;
}
toDataURL(lpif_anchor_tag_href, function (dataUrl) {
console.log(dataUrl);
});
toDataURL(lpif_anchor_tag_href_two, function (dataUrl) {
console.log(dataUrl);
});