【发布时间】:2018-12-16 07:17:55
【问题描述】:
我真的需要一些帮助来解决使用 BootstrapValidator 的表单提交问题。
我有以下代码使用 AJAX 调用页面,当我获得成功响应时,它会使用 location.reload(true) 刷新页面。
$('#indstillingForm1')
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
$.ajax({
url: "../bin/gem_indstilling.php",
type: "POST",
processData: false,
contentType: false,
dataType:"json",
data: form_data,
cache: false,
success: function(response) {
if(response.result === "success") {
$('html, body').animate({scrollTop:0}, 'slow');
setTimeout(function(){
location.reload(true);
}, 2000);
} else if(response.result === "failure") {
}
})
});
});
问题是.on('success.form.bv') 代码被多次触发。
我该如何解决这个问题?
【问题讨论】:
标签: jquery ajax bootstrapvalidator