在 Webkit 浏览器中提交 Ajax 表单后,Ambethia Recaptcha 无法重新呈现

发布于 2024-09-11 05:25:09 字数 659 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鸠魁 2024-09-18 05:25:09

我遇到了同样的问题,无法让它与 webkit 浏览器中的 recaptcha_tags 一起使用。

最后我遵循官方指南并这样写(在 HAML 中)....


  1. 在布局头标签中:

    = javascript_include_tag "http://api.recaptcha.net/js/recaptcha_ajax.js"
    
  2. 在渲染的部分中
    通过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) ....


  1. in the layouts head tag:

    = javascript_include_tag "http://api.recaptcha.net/js/recaptcha_ajax.js"
    
  2. in the partial which was rendered
    via ajax:

    #dynamic_recaptcha
    :javascript
      Recaptcha.create('YOURPLUBLICKEY', document.getElementById('dynamic_recaptcha') , '')
    

http://code.google.com/apis/recaptcha/docs/display.html

遇见了你 2024-09-18 05:25:09

如果有人遇到这个问题, ajax: true 为我解决了这个问题。我使用rails 3.2.13和recaptcha 0.3.5

=recaptcha_tags(display: {theme: 'clean'}, ajax: true)

if anybody is having this issue, ajax: true did the trick for me. Im using rails 3.2.13 and recaptcha 0.3.5

=recaptcha_tags(display: {theme: 'clean'}, ajax: true)
梦情居士 2024-09-18 05:25:09

我通过以下方法解决了这个问题:

将运行时ajax无法加载的脚本放入 head:

<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script>

可选主题:

<script type="text/javascript">var RecaptchaOptions = {"theme":"clean"};</script>

然后使用 evalScripts 选项在 true

new Ajax.Updater('example_div', '/example', { parameters: {text: $F('example_text')}, evalScripts: 'true'});

I solve it by the following method:

putting the scripts that won't load by ajax at runtime in head:

<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script>

Optionally the theme:

<script type="text/javascript">var RecaptchaOptions = {"theme":"clean"};</script>

Then calling Ajax.Updater with evalScripts option at true:

new Ajax.Updater('example_div', '/example', { parameters: {text: $F('example_text')}, evalScripts: 'true'});
渡你暖光 2024-09-18 05:25:09

在 HTML 文件中。

recaptcha_tags(ajax: true)

AJAX 请求中的

$.ajax({
  url: "/users/sign_in",
  type: "POST",
  data: { 
 
  email_id: user_email_id,
  password: pwd,
  type: login_type,
  browser_det: browser_details,
  login_type: "firebase",
  "g-recaptcha-response": grecaptcha.getResponse()
  }

in HTML file.

recaptcha_tags(ajax: true)

in AJAX request

$.ajax({
  url: "/users/sign_in",
  type: "POST",
  data: { 
 
  email_id: user_email_id,
  password: pwd,
  type: login_type,
  browser_det: browser_details,
  login_type: "firebase",
  "g-recaptcha-response": grecaptcha.getResponse()
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文