如何在保留 reCaptcha 脚本的同时使用 jQuery/AJAX 加载 reCaptcha 表单? [英] How can I load a reCaptcha form using jQuery/AJAX while leaving the reCaptcha scripts in place?
问题描述
我使用 JQuery/AJAX 将我的联系表单加载到我的页面中.
I load my contact form into my page with JQuery/AJAX.
联系表单包含 reCaptcha 脚本.
The contact form contains the reCaptcha scripts.
不幸的是,JQuery 在将脚本标签插入到我的页面之前删除了它们.需要这些脚本标签,因为它们输出验证码.现在我加载的表单没有验证码.
Unfortunately, JQuery removes the script tags before inserting them into my page. These script tags are needed because they output the captcha. now my loaded form has no captcha.
推荐答案
该链接拥有您需要的一切:http://code.google.com/apis/recaptcha/docs/display.html
The link has all you need: http://code.google.com/apis/recaptcha/docs/display.html
无法在ajax中添加脚本.您应该在之前添加以下行:
You can't add the script in ajax. You should add the following line before :
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
然后,您可以通过添加以下代码在您的 js 代码中动态创建一个 recaptcha 表单:
Then, you can dynamically create a recaptcha form in your js code by using adding the following code:
Recaptcha.create("your_public_key",
"element_id",
{
theme: "red",
callback: Recaptcha.focus_response_field
}
);
这篇关于如何在保留 reCaptcha 脚本的同时使用 jQuery/AJAX 加载 reCaptcha 表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!