Google Invisible Recaptcha Using Jquery Ajax and PHP
我按照上面的链接使用jQuery,AJAX和PHP获取google invisible recaptcha。验证是成功的,它只是接受我作为人类,而不提示验证图像。有时它会验证并要求图像挑战。 我已将google api https更改为http但仍有问题。
var onloadCallback = function(){
grecaptcha.render("emplacementRecaptcha",{
"sitekey": "Site Key",
"badge": "inline",
"type": "image",
"size": "invisible",
"callback": onSubmit
});
};
var onSubmit = function(token){
var name = $("#name").val();
var address = $("#address").val();
var state = $("#state").val();
var zip = $("#zip").val();
var telephone = $("#telephone").val();
var email = $("#email").val();
var comments = $("#comments").val();
var spinner = $('#spinner');
spinner.css('display','block');
$.ajax({
type: "POST",
url: location.href,
data:{
name: name,
address: address,
state: state,
zip: zip,
telephone: telephone,
email: email,
comments: comments,
userJetonRecaptcha: token
},
success: function(response){
$("#successMsg").show();
spinner.css('display','none');
return false;
},
error: function(){
console.log("something went wrong");
grecaptcha.reset();
}
});
};
function validate(event){
event.preventDefault();
console.log("btn clicked");
var name = $("#name").val();
var zip = $("#zip").val();
var email = $("#email").val();
var comments = $("#comments").val();
if(name == ''){
alert('Please Enter Your Name');
return false;
}
if(zip == ''){
alert('Please enter Valid Zip code.');
return false;
}
if(email == ''){
alert('Please Enter Your email address');
return false;
}
if(comments == ''){
alert('Please Comment or Message');
return false;
}
grecaptcha.execute();
}
function onload(){
var element = document.getElementById("boutonConnexion");
element.onclick = validate;
}

<script src="http://google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"></script>
<form name="contactfrm" id="contactfrm" action="" method="post">
<input id="boutonConnexion" type="submit" class="form-control" value="Submit"><i id="spinner" class="fa fa-spin fa-spinner"></i>
</form>
<div id="emplacementRecaptcha"></div>
<script>onload();</script>
&#13;