【问题标题】:jQuery / php refresh CAPTCHAjQuery/php 刷新验证码
【发布时间】:2013-08-23 11:12:44
【问题描述】:

我在我的联系我们页面中使用了一个简单的验证码。我想使用 javascript / jQuery 添加刷新功能。 制作验证码图像的函数位于单独的文件中。 当页面加载验证码运行良好但我无法进行刷新。 我的代码是:

<head>
...
    $(document).ready(function(){
        $('#reload').click(function(){
            $("#captcha").load("functions/captcha.php"); // function that creates the NEW CAPTCHA
            $("#captcha").attr("src", "images/captcha.jpg?"+(new Date()).getTime());
        });
    });

...
</head>
<body>
<?php 
  require(functions/captcha.php);
 ?>

  // form
  ...
  <label for="captcha_code">ENTER CAPTCHA</label>
    <img src="images/captcha.jpg" id="captcha" /> 
      <a id='reload'>Refresh now</a>
        <input type="text" name="captcha_code" value="captcha_code">
  ...

非常感谢您的帮助。 感谢您的阅读。

【问题讨论】:

    标签: php jquery captcha


    【解决方案1】:

    您应该在“functions/captcha.php”完全加载之前等待。

    试试这个例子:

    <div id="loader"></div> <!-- hide this div by css -->
    $('#reload').click(function() {
         $("#loader").load("functions/captcha.php",  function() {
              $("#captcha").attr("src", "images/captcha.jpg?refr="+(new Date()).getTime());
         }); 
    });
    

    但是创建输出图像的functions/captcha.php 并刷新src 参数不是更好吗?

    【讨论】:

    • 谢谢 Tomasz 但它仍然不起作用。你是对的,但首先我想弄清楚如何创建一个新的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    • 2018-12-02
    • 2016-01-22
    • 2011-03-30
    • 1970-01-01
    相关资源
    最近更新 更多