【问题标题】:how to refresh simple captcha如何刷新简单的验证码
【发布时间】:2013-02-15 20:56:53
【问题描述】:

我在 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()"/>

我收到的警报中的响应是这样的 --�PNGIHDR�2�3�j

“captchaImg”作为 URL-Pattern 添加到我的 web-xml 中的 servlet-mapping 中。谁能帮助我如何刷新验证码。

【问题讨论】:

  • img 没有内部 HTML。
  • 那么请告诉我我必须做些什么才能让它成为仪式
  • 你在使用一些服务器端技术吗?像 PHP、Python 等?
  • 嘿,我知道它不需要任何 ajax 调用我只是添加了这段代码 onclick="document.getElementById('captcha').src='captchaImg?'+(new Date().getTime( ));"这个东西是最重要的?'+(new Date().getTime());

标签: javascript ajax captcha simplecaptcha


【解决方案1】:

不需要任何 ajax 调用,我只是添加了这段代码

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

这个东西是最重要的一个:?'+(new Date().getTime());

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    • 2016-01-22
    • 2013-03-04
    • 2020-05-01
    • 2013-08-23
    相关资源
    最近更新 更多