te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Can't refresh reCaptcha on JQuery Ajax return - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't refresh reCaptcha on JQuery Ajax return - Stack Overflow

programmeradmin3浏览0评论

I'm having a devil of a time trying to get Ajax to automatically refresh on a JQuery AJAX callback. I have a ment box with the messages being refreshed posted immediately upon validation of reCaptcha and it would be nice if the reCaptcha could refresh automatically in case someone wants to add another ment immediately afterward. Here's my return function:

 $.post(url, formData, function(data) {
        if (returnString.match(/^Error:/)) {
          $("#interactionResults").html(data).show().fadeOut(6000);
        }
        else if (postNumber == 0) {
          $('#newCommentDisplay').html(returnString).show();
          $.post("", "Recaptcha:reload()");   
        }

When I use:

$.post("", "Recaptcha:reload()"); 

I get an error:

XMLHttpRequest cannot load . Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin. 

Fair enough, so I try to change that line with this one:

$('#recaptcha_reload_btn').trigger('click'); 

and still nothing is happening. Does anyone know what's going on?

I'm having a devil of a time trying to get Ajax to automatically refresh on a JQuery AJAX callback. I have a ment box with the messages being refreshed posted immediately upon validation of reCaptcha and it would be nice if the reCaptcha could refresh automatically in case someone wants to add another ment immediately afterward. Here's my return function:

 $.post(url, formData, function(data) {
        if (returnString.match(/^Error:/)) {
          $("#interactionResults").html(data).show().fadeOut(6000);
        }
        else if (postNumber == 0) {
          $('#newCommentDisplay').html(returnString).show();
          $.post("http://www.google./recaptcha/api", "Recaptcha:reload()");   
        }

When I use:

$.post("http://www.google./recaptcha/api", "Recaptcha:reload()"); 

I get an error:

XMLHttpRequest cannot load http://www.google./recaptcha/api. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin. 

Fair enough, so I try to change that line with this one:

$('#recaptcha_reload_btn').trigger('click'); 

and still nothing is happening. Does anyone know what's going on?

Share Improve this question edited Dec 12, 2019 at 5:22 sideshowbarker 88.2k29 gold badges215 silver badges211 bronze badges asked Apr 3, 2012 at 23:31 John BowlingerJohn Bowlinger 1,5794 gold badges12 silver badges14 bronze badges 5
  • ah, by "nothing is happening" do literally mean nothing, or do you still talk of a Google error? – marue Commented Apr 4, 2012 at 8:09
  • Yeah, I literally mean nothing. Sorry I didn't make that clearer. – John Bowlinger Commented Apr 4, 2012 at 13:11
  • Then you need to show your click-handler. Has to be some problem there. – marue Commented Apr 4, 2012 at 14:02
  • @marue It's in an Iframe which is what I think may be tripping me up. I think I may need to send a JSON object back to Google. Here's the iframe: <iframe src="google./recaptcha/api/…" height="300" width="500" frameborder="0"></iframe><br/> – John Bowlinger Commented Apr 5, 2012 at 4:18
  • Hm, it's not so easy to catch events from an iframe, i'm not even sure if it is possible. If you have outside that iframe, you could use the answer in this post stackoverflow./questions/4249809/… – marue Commented Apr 5, 2012 at 8:18
Add a ment  | 

6 Answers 6

Reset to default 6

in my html I have :

<div class="g-recaptcha" id='recaptcha' data-sitekey="xxxxxxxxxx"></div>

I use grecaptcha.reset();

example: if (typeof $('#recaptcha') != "undefined") { grecaptcha.reset(); }

Use

jQuery("#recaptcha_reload").click(); 

"#recaptcha_reload", the image itself, is the trigger. #recaptcha_reload_btn will NOT work, because the a-tag is NOT the trigger.

Recaptcha.reload();

( Recaptcha is already loaded )

if you are using new recaptcha 2.0 use this: for code behind:

ScriptManager.RegisterStartupScript(this, this.GetType(), "CaptchaReload", "$.getScript(\"https://www.google./recaptcha/api.js\", function () {});", true);

for simple javascript

<script>$.getScript(\"https://www.google./recaptcha/api.js\", function () {});</script>

You have not bound a click handler to your element. From the jQuery docs:

.trigger( eventType [, extraParameters] )

Description: Execute all handlers and behaviors attached to the matched elements for the given event type.

If you have not attached a handler to your element before calling trigger, there is no click handler to execute.

edit:

When you write $('#recaptcha_reload_btn').bind('click'); you actually set up a click handler, but one that does nothing. You have to tell that clickhandler what to do:

$('#recaptcha_reload_btn').bind('click',function() {
    alert('you just clicked me');
};

If you do not set up a callback handler, the event is just registered but does not trigger any action. Combine this with the solution from this question Reload an iframe with jQuery and you should have your recaptcha doing what you want:

$('#recaptcha_reload_btn').bind('click',function() {
    var iframe = document.getElementById('#recaptcha'); //use your own selector here!
    iframe.src = iframe.src;
};
$( "#recaptcha_reload_btn" ).click();
发布评论

评论列表(0)

  1. 暂无评论