2012-04-03 3 views
4

JQuery AJAX 콜백에서 자동으로 Ajax를 새로 고치려고 애쓰는 악마가 있습니다. 난 reCaptcha의 유효성을 즉시 게시 된 메시지를 새로 고침과 함께 의견 상자가 있고 reCaptcha 누군가가 즉시 나중에 또 다른 의견을 추가하려는 경우 자동으로 새로 고칠 수 있다면 좋을 것입니다. JQuery Ajax에서 reCaptcha를 새로 고칠 수 없습니다. return

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

내가 오류 얻을 : 내가 사용하는 경우

$.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.com/recaptcha/api", "Recaptcha:reload()"); 
     } 

: 충분히

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

박람회, 그래서 나는이 하나 그 라인을 변경하려고 : 여기 내 반환 함수의

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

아직 아무 것도 없습니다. pening. 아무도 무슨 일이 일어나는지 알아?

+0

아에 대한

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

: 뒤에 코드를 : 0이 사용합니까? – marue

+0

그래, 나는 문자 그대로 아무것도 의미하지 않는다. 미안해. 내가 더 명확하게하지 않았어. –

+0

그러면 클릭 핸들러를 보여줘야합니다. 거기에 어떤 문제가 있어야합니다. – marue

답변

-1

요소에 클릭 처리기를 바인딩하지 않았습니다. JQuery와 문서에서 : 당신은 트리거를 호출하기 전에 요소에 대한 처리기를 부착하지 않은 경우

.trigger(eventType [, extraParameters])

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

, 실행 할 클릭 핸들러가 없다.

편집 :

당신은 당신이 실제로 클릭 핸들러를 설정 $('#recaptcha_reload_btn').bind('click');,하지만 아무것도하지 않는 한 물품. 당신은 무엇을해야 하는지를 그 경우 clickHandler에게 있습니다

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

당신이 콜백 핸들러를 설정하지 않은 경우, 이벤트가 단지 등록되어 있지만 액션을 트리거하지 않습니다. 이 질문에 Reload an iframe with jQuery에서 솔루션이 결합하고 당신은 당신의 reCAPTCHA를 당신이 원하는 일을해야한다 :

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

$ ('# recaptcha_reload_btn') 추가. bind '); ( –

-1
$("#recaptcha_reload_btn").click(); 
+0

Proximo의 대답은 올바른 것입니다. $ ("# recaptcha_reload") click();' –

2
Recaptcha.reload(); 

(reCAPTCHA를 이미로드)

3

사용

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

"#recaptcha_reload", 이미지 자체가 트리거입니다. a 태그가 트리거가 아니기 때문에 #recaptcha_reload_btn이 작동하지 않습니다. 내 HTML에서

+0

+1은 captcha를 표시하는 데 사용되는 라이브러리와 상관없이 작동하기 때문에 +1하지만, –

6

내가 가진 :

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

내가 사용 grecaptcha.reset();

예 : 경우 (! 대해서 typeof $ ('#의 reCAPTCHA를') = "정의되지 않은") { grecaptcha.reset() ; }

+0

+0

답변을 업데이트하려면 의견 대신 대답을 편집하십시오. – Ram

+0

2015 년 4 월 (또는 그 이전) 현재, 귀하는 자바 스크립트 라이브러리를 사용하시는 것이 좋습니다. Recaptcha.reload(); 구글은 새로운 보안 문자를 가지고 있는데,'grecaptcha.reset();'을 사용하면 나에게 도움이되었던 정답이된다. –

0

새로운 recaptcha 2를 사용하는 경우."아무 일이 없다"에 의해 문자 그대로 아무 의미합니까, 또는 당신은 여전히 ​​구글 오류로 이야기합니까, 간단한 자바 스크립트

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