Reload catcha image

View: New views
1 Messages — Rating Filter:   Alert me  

Reload catcha image

by Frank Hamilton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I tray to reload a captcha imagen by XMLHttpRequest. I have a servlet that return a imagen, when i put this code in my page   a catpcha image appear.

My js funtion to reload captcha is :

function myfunction()
{
                 var myhttp=new XMLHttpRequest();
                 myhttp.open("GET","/captcha.jpg",true);
                 myhttp.onreadystatechange=function () {
                 if (myhttp.readyState==4)
                 {
                        alert(myhttp.responseText);
                 }
                 }
               
                myhttp.send(null);
}

The value of myhttp.responseText is a bytes that represent the image, some thing like this:
�PNG

IHDR�dL��\
�IDATx��up����N�(,��{p
��;U�K��� Hp
����]ޯ�z]�v#C�
......

I suppose that I need  innerHTML to put the new image in my page, but how?

Html code:

<div id="captcha">
 
</div>
<input type="button" value="reload image" onclick="myfunction()" />


TIA.