您缺少
onSubmit()回调函数。
要重新排列您的js以利用该功能,这将是您的新js块:
<script>// this block must be defined before api.js is includedfunction onSubmit(token) { var fields = $('#contact-form').serializeArray(); // get your form data fields.push({name: "g-recaptcha-response", value: token});// add token to post $.ajax({ type: "POST", url: "assets/php/contact.php", data: fields, dataType: 'json', success: function(response) { if(response.status) { $('#contact-form input').val(''); $('#contact-form textarea').val(''); } $('#response').empty().html(response.html); } }); grecaptcha.reset();// to reset their widget for any other tries}</script><script src="https://www.google.com/recaptcha/api.js" async defer></script><script>// this block can be defined anywhere$(function() { $("#contact-submit").on('click',function() { // call grecaptcha.execute, which causes recaptcha to // do its thing and then calls onSubmit with the token grecaptcha.execute();// does not return anything directly return false; });});</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)