HTML:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- Suggest Modal -->
<div id="suggestModal" class="modal fade anycard-modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" id="modal-close" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Business Suggestion</h4>
</div>
<div class="modal-body">
<div id="suggest-area">
<form id="suggestion-form">
<div class="form-group">
<span class="aster">*</span>
<label for="s-name">Name:</label>
<input type="text" class="form-control" id="s-name">
</div>
<div class="form-group">
<span class="aster">*</span>
<label for="s-email">Email:</label>
<input type="text" class="form-control" id="s-email">
</div>
<div class="form-group">
<span class="aster">*</span>
<label for="s-idea">Business suggestion:</label>
<textarea class="form-control" id="s-idea"></textarea>
</div>
<div class="form-group">
<div class="g-recaptcha" data-sitekey="6LdoqQoUAAAAAHNBx5GxMXYq_8FfxZMUf09bn7QI"></div>
</div>
<button type="submit" class="btn btn-primary">Submit your suggestion</button>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div><!-- /Suggest Modal -->
我正面临谷歌reCAPTCHA的问题。它没有正确加载。然后我检查浏览器,看看问题出现在iframe上。它的来源未定义。
<iframe src="undefined?autoplay=1" title="recaptcha widget" width="304" height="78" role="presentation" frameborder="0" scrolling="no" name="undefined"></iframe>
下面给出了Ajax代码,我使用或表单提交。 Ajax的:
$('#suggestion-form').submit(function(e) {
e.preventDefault();
var form_data = new FormData();
var name = $('#s-name').val();
var email = $('#s-email').val();
var suggestion = $('#s-idea').val();
form_data.append('name', name);
form_data.append('email', email);
form_data.append('suggestion', suggestion);
$.ajax({
url: 'default.php?controller=queries&action=addsuggestion',
type: 'POST',
data: form_data,
processData: false,
contentType: false,
success: function(data) {
if(data.success) {
$('#suggest-area')
.find('.alert').remove()
.end()
.prepend('<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Thank you for your valuable suggestion</div>');
window.setTimeout(function(){
//$('#suggestModal').modal('hide');
$('#modal-close').click();
$('#suggestion-form')[0].reset();
$('#suggest-area').find('.alert').remove();
}, 2000);
}else{
var error = '';
switch(data.error) {
case 'fillFields':
error = 'Please fill in all the fields';
break;
case 'invalidEmail':
error = 'The provided email is invalid';
break;
}
$('#suggest-area')
.find('.alert').remove()
.end()
.prepend('<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><strong>Error:</strong> '+error+'.</div>');
}
}
});
我无法理解为什么iframe src未定义。由于未定义的iframe源,reCAPTCHA未正确加载。请帮我解决这个问题。