尝试使用表单中的验证码序列化表单。
这是我序列化表单的方法:
var serializedform = $('form.af').serialize();
这是我的表单示例:
<form class = 'af'>
<input name='name' id = 'name'>
<input name='lastname' id = 'lastname'>
<div id = 'recaptchadiv'>
<input name='recaptcha_response_field' id = 'recaptcha_response_field'>
<input name='recaptcha_challenge_field' id = 'recaptcha_challenge_field'>
<noscript>
<input name='recaptcha_response_field' id = 'recaptcha_response_field'>
<input name='recaptcha_challenge_field' id = 'recaptcha_challenge_field'>
</noscript>
</div>
<button name = 'submit'>
</form>
问题来自于由recaptcha自动注入(inject)的recaptcha noscript block 。 该 block 包含 recaptcha_response_field 和 recaptcha_challenge_field 的副本。
因此,当我序列化此表单时,noscript block 输入的值会覆盖真实的 recaptcha_response_field 和 recaptcha_challenge_field 值。
有没有办法使用 jquery 序列化表单,同时跳过 noscript block ?
谢谢:)
最佳答案
您可以使用 jQuery remove <noscript>
在表单序列化之前添加标签 - 显然,到那时它们就不是必需的了。像这样的事情:
var $form = $('form.af');
$form.find('noscript').remove();
var serializedform = $form.serialize();
关于javascript - Jquery表单与recaptcha序列化问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5138153/