The problem is that recaptcha code run with document.write()
method. When you call ajax, you can't use that method because of ajax
. For example, data-remote
in modal use ajax internally.
If you run the code in chrome, you can see the warning below.
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
Google provide other way of recaptcha for solving the problem. You can add the script in your index.jsp
first.
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
And then, replace the code in login.jsp
.
<%
ReCaptcha c = ReCaptchaFactory.newReCaptcha("YOUR_API_KEY", "YOUR_TOKEN", false);
out.print(c.createRecaptchaHtml(null, null));
%>
to...
<div id="recaptcha"></div>
<script>
Recaptcha.create("YOUR_API_KEY", // update with your api key
"recaptcha",
{
theme: "red",
callback: Recaptcha.focus_response_field
}
);
</script>
That's all. ReCaptcha will show on the modal.
FYI, you need to verify the form. Verifying the User's Answer Without Plugins will be helpful.