I am using the below code to call a captcha generating web service. The response is fetched correctly but when trying to append the result under a div the image appears as garbage text
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
window.alert(xmlHttp.getAllResponseHeaders());
document.getElementById("captchaDiv2").innerHTML = "<img src=\"data:image/png;base64," + xmlHttp.responseText + "\"/>";
}
}
xmlHttp.open("GET", captchaSrc, true); // true for asynchronous
xmlHttp.send(null);
The response header is the below, as you can see the type is image/png
Yet when I try to import it inside the html I am getting the below:
Can you please advise what could be the root cause behind this? I already tried btoa() with and without encoding... No results.