I have implemented the following code to integrate a captcha generating web service. The response data is successfully obtained, but when I attempt to display the result within a div element, the image appears as distorted 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 indicates that the type is image/png:
https://i.stack.imgur.com/HG4gK.png However, upon attempting to insert it into the HTML, the output looks like this: https://i.stack.imgur.com/vR8Vp.png
Could you please provide insights on what might be causing this issue? I have already attempted using btoa() with and without encoding, but it did not yield any positive results.