Update Simple Security Code

I am using a simple captcha in my JSP. Everything is fine. I want to provide an update button next to captcha so that the user can change captcha. Captcha only changes when the full page is refreshed, but I do not want to reload the entire page for it.

I need your suggestions on how I can implement this, for example, using AJAX or JQuery to reload only the captcha page, not the whole page.

+5
source share
3 answers
<script type="text/javascript">
    function reloadCaptcha(){
        var d = new Date();
        $("#captcha_image").attr("src", "/captcha_generator.jsp?"+d.getTime());
    }
</script>
   ...
<img id="captcha_image" src="/captcha_generator.jsp" alt="captcha image" width="200" height="50"/>
<img src="reload.jpg" onclick="reloadCaptcha()" alt="reload"width="40" height="40"/>
+2
source

, SimpleCaptcha, 'src' captcha <img>. - onClick :

var img = document.getElementById('captcha_id');// captcha_id is the id attribute of your caprtcha img
img.src = 'Some new captcha url';
0
<script type="text/javascript">
    function reloadCaptcha(){
        var d = new Date();
        $("#captcha_image").attr("src", "captcha.php?"+d.getTime());
    } </script>

<img id="captcha_image" src="captcha.php" alt="captcha image" width="90" height="33"/> <img src="images/refresh.png" alt="reload" width="22" height="22" border="0" onclick="reloadCaptcha()" />
0
source

All Articles