Refresh Simple Captcha
captcha, html, java, javascript, jsp
Solution
<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"/>
Problem
I am using simple captcha in my JSP. Everything is OK. I want to provide a refresh button alongside of captcha to allow user to change the captcha. Captcha changes only on refreshing the complete page but I don't want to reload whole page for it. I need your suggestions on how I can implement this like using AJAX or JQuery to reload only the captcha, not whole page.