2013-03-01 88 views
2

我在eclipse IDE中的库中使用了simplecaptcha 1.2.1 jar文件,它的工作正常。没有选项刷新验证码,所以我添加了下面的代码,但它不工作。如何刷新简单的验证码

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(); 
} 

和我的HTML部分是

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

在警报即时得到的是输入反应有些什么样的这个--PNGIHDR23j

“captchaImg” 被添加作为web-xml中的servlet映射中的URL模式。任何人都可以帮助我如何刷新验证码。

+0

的'img'没有内在的HTML。 – Amberlamps 2013-03-01 11:17:30

+0

那么请告诉我我已经做好让它成为仪式 – amit 2013-03-01 11:20:59

+0

您是否使用了一些服务器端技术?像PHP,Python等? – Passerby 2013-03-01 11:36:36

回答

1

无需任何Ajax调用我只是说这个代码

onclick="document.getElementById('captcha').src='captchaImg?'+ 
    (new Date().getTime());" this thing is most important one ?' 
      +(new Date().getTime());