我在这里看到了很多问题和答案,但似乎都无法解决我的问题。我有一个表单,它是从ajax加载调用加载到名为dynamic-content的div类中的。基本上,如果按下表单提交按钮,我希望它在ajax中重新加载此表单,以便进行php表单验证。我的问题是,当提交发生时,我会调用ajax加载以通过javascript重新加载,但它不会触发,而是会返回当前索引页面。我的JS如下:
$(document).ready(function () {
//Handle AJAX request from sidebar buttons
var trigger = $('.submit-btn'),
container = $('.dynamic-content');
$(".add-customer-form-btn").submit(function() {
// do something...
alert('test');
container.load('customers/customersaddform.php',$("form").serializeArray());
return false;
});
});
customersaddform.php中的我的html表单,该表单已加载到位于主索引文件中的动态内容div中。
<?php
//FORM VALIDATION CHECKS
?>
<form action="" method="post">
<div class="form-field add-customer-form">
<div class="container-fluid">
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<h4>Account Information</h4>
<div class="row">
<div class="col-md-6 label-container">
<div class="input-group input-group-icon">
<input type="text" placeholder="First Name" name="first-name" required/>
<div class="input-icon"><i class="fa fa-user"></i></div>
<div class="input-error-msg"><?php echo $first_name_err;?></div>
</div>
</div>
<div class="row">
<div class=col-md-12 label-container">
<input type="submit" class="add-customer-form-btn submit-btn" value="Submit">
</div>
</div>
</div>
</div>
</form>