admin管理员组文章数量:1321066
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 plete 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.
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 plete 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.
Share Improve this question edited Apr 14, 2012 at 7:48 Andrew Thompson 169k41 gold badges222 silver badges436 bronze badges asked Apr 14, 2012 at 7:37 SandySandy 14.1k22 gold badges79 silver badges111 bronze badges 03 Answers
Reset to default 3<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"/>
I don't remember how SimpleCaptcha works, but usually, you should simply change the 'src' attribute of you captcha <img>
. Something like this on the onClick
of your refresh button:
var img = document.getElementById('captcha_id');// captcha_id is the id attribute of your caprtcha img
img.src = 'Some new captcha url';
<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()" />
本文标签: javaRefresh Simple CaptchaStack Overflow
版权声明:本文标题:java - Refresh Simple Captcha - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742092341a2420342.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论