在 Webkit 浏览器中提交 Ajax 表单后,Ambethia Recaptcha 无法重新呈现
我的 Rails 应用程序中有一个 Ajax 表单,其中包含 Ambethia Recaptcha gem 中的帮助程序提供的 Recaptcha 标记:
recaptcha_tags :ajax => true
提交时,表单会执行一个创建操作,该操作会使用包含以下内容的 create.js.erb 进行响应
$('#message-form').replaceWith("<%= escape_javascript(render('message')) %>");
: “message”部分包含与最初呈现的相同的表单标记,包括 recaptcha_tags,但如果此时验证中存在错误,也可能会显示。
在 Firefox 中,表单将重新呈现并显示刷新的验证码。但由于某种原因,在 Webkit 浏览器(Safari 和 Chrome)中,“dynamic_recaptcha”Recaptcha 元素被清空,就好像 Recaptcha.create(public_key, element_id) 永远不会被调用一样。
在 Safari 开发者控制台中,我可以调用 Recaptcha.create(public_key, element_id) 并重新生成验证码。
谁能告诉我这是怎么回事?谢谢。
I have an Ajax form in my Rails app that contains the Recaptcha markup as provided by the helper in the Ambethia Recaptcha gem:
recaptcha_tags :ajax => true
On submit, the form hits a create action, which responds with the create.js.erb that contains the following:
$('#message-form').replaceWith("<%= escape_javascript(render('message')) %>");
The 'message' partial contains the same form markup that was originally rendered, including recaptcha_tags, but may also display if there were errors in the validation at this point.
In Firefox, the form gets re-rendered and displays a refreshed Captcha. But for some reason, in Webkit browsers (Safari and Chrome), the 'dynamic_recaptcha' Recaptcha element gets emptied, as if Recaptcha.create(public_key, element_id) never gets called.
In the Safari Developer console, I am able to call Recaptcha.create(public_key, element_id) and regenerate a Captcha.
Can anyone tell me what's going on here? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,无法让它与 webkit 浏览器中的 recaptcha_tags 一起使用。
最后我遵循官方指南并这样写(在 HAML 中)....
在布局头标签中:
在渲染的部分中
通过ajax:
<前><代码>#dynamic_recaptcha
:javascript
Recaptcha.create('YOURPLUBLICKEY', document.getElementById('dynamic_recaptcha') , '')
http://code.google.com/apis/recaptcha/docs /显示.html
i had the same problem and couldn`t get it to work with the recaptcha_tags in webkit browsers.
finally i followed the official guideline and wrote it like that (in HAML) ....
in the layouts head tag:
in the partial which was rendered
via ajax:
http://code.google.com/apis/recaptcha/docs/display.html
如果有人遇到这个问题, ajax: true 为我解决了这个问题。我使用rails 3.2.13和recaptcha 0.3.5
if anybody is having this issue, ajax: true did the trick for me. Im using rails 3.2.13 and recaptcha 0.3.5
我通过以下方法解决了这个问题:
将运行时ajax无法加载的脚本放入 head:
可选主题:
然后使用 evalScripts 选项在 true:
I solve it by the following method:
putting the scripts that won't load by ajax at runtime in head:
Optionally the theme:
Then calling Ajax.Updater with evalScripts option at true:
在 HTML 文件中。
recaptcha_tags(ajax: true)
AJAX 请求中的
in HTML file.
recaptcha_tags(ajax: true)
in AJAX request