我制作了一个Ajax表单,但在几天之前,我添加了Invisible Google Captcha。但现在,Google Captcha代码会重定向用户以形成action
网址。
这是我的代码之前添加Captcha:
$("form.formajax").submit(function(e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr("action");
var form = $(this); // Add this line
$.post(url, data, function(data) {
$(form).children(".signupresult").html(data.signupresult);
});
return false;
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form class="formajax" method="post" action="admin/login/logincheck.php">
<input type="text" placeholder="username">
<input type="submit" />
</form>
&#13;
以下是添加Captcha
后的代码
function onSubmit(token) {
document.getElementById("i-recaptcha").submit();
}
$("form.formajax").submit(function(e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr("action");
var form = $(this); // Add this line
$.post(url, data, function(data) {
$(form).children(".signupresult").html(data.signupresult);
});
return false;
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<form id='i-recaptcha' class="formajax" method="post" action="admin/login/logincheck.php">
<input type="text" placeholder="username">
<input type="submit" class="g-recaptcha" data-sitekey="6Lcjvi4UAAAAAIR7_ckItF2HfMEFHx427WUDdGDk" data-callback="onSubmit" />
</form>
&#13;
可能是onSubmit
函数导致问题。我怎么能把这个表格变成ajax?