Question

I have simplecaptcha 1.2.1 jar file in my libraries in eclipse IDE and its working fine. there was no option to refresh the captcha so i hav added the following code but its not working.

function refreshCaptcha()
 {
     var xmlhttp;
     if (window.XMLHttpRequest)
       {
       xmlhttp=new XMLHttpRequest();
       }
     else
       {
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     xmlhttp.onreadystatechange=function()
       {
       if (xmlhttp.readyState==4)
         {
         if(xmlhttp.status==200)
          {
          alert(xmlhttp.responseText);                  
         document.getElementById("captcha").innerHTML=xmlhttp.responseText;
         }
         }
       }
     xmlhttp.open("GET","captchaImg",true);
     xmlhttp.send();
 }

and my html part is

        <img src="captchaImg" id="captcha"/>
        <img src="resources/images/refresh.jpeg" onclick="refreshCaptcha()"/>

the respone in the alert i m getting is some what like this --�PNGIHDR�2�3�j

"captchaImg" is added as URL-Pattern in my servlet-mapping in web-xml. can anyone help me how to refresh the captcha.

Was it helpful?

Solution

no need of any ajax call i just added this code

onclick="document.getElementById('captcha').src='captchaImg?'+
         (new Date().getTime());" 

this thing is most important one: ?'+(new Date().getTime());

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top