参考文章
ajax的重复提交问题,和bootstrapValidator校验冲突问题解决办法
问题代码
<div class="modal-footer">
<button type="submit" class="btn btn-green btn-sm">新增</button>
</div>
<script type="text/javascript">
var fields = {
password: {validators: {notEmpty: {message: '登录密码不能为空'}}},
//其余校验...
}
$('#serviceForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: fields
}).on("success.form.bv",function(e){
e.preventDefault();
//ajax提交的代码...
});
</script>
改后代码
<div class="modal-footer">
<button type="button" class="btn btn-green btn-sm" id="reportButton">新增</button>
</div>
<script type="text/javascript">
var form = $('#serviceForm');
var fields = {
password: {validators: {notEmpty: {message: '登录密码不能为空'}}},
//其余校验...
}
$(document).ready(function () {
form.bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: fields
})
});
$("#reportButton").click(function (e) {
var bmz= form.data('bootstrapValidator');
bmz.validate();
if (bmz.isValid()) {
//ajax提交的代码...
}
})
</script>