在jQuery中,我在一个bootstrap表单上使用$.ajax方法和jqBootstrapValidation插件,但是验证不能正常工作。我正在使用
$('#updatenamebutton').click(function(event)
{
event.preventDefault();
}preventDefault正在停止验证,但我不想实际提交值,所以我使用event.preventDefault();。有什么想法吗?
发布于 2013-04-15 01:10:44
您只需将ajax函数放入jqBootstrapValidation submitSuccess回调中。
您不需要在表单上绑定像" submit“或"click”这样的触发器,因为jqBootstrapValidation将处理提交事件。
以下代码不言自明:
$(function() {
$('form[name="contact"]').find('input,select,textarea').not('[type=submit]').jqBootstrapValidation({
submitSuccess: function ($form, event) {
$.ajax({
type: 'POST',
url: $form.attr('action'),
data: $form.serialize(),
success: function(data)
{
// just to confirm ajax submission
console.log('submitted successfully!');
}
});
// will not trigger the default submission in favor of the ajax function
event.preventDefault();
}
});
});有关该插件的更多详细信息,请访问:http://reactiveraven.github.io/jqBootstrapValidation/
发布于 2013-03-30 15:48:36
您必须执行如下操作:
$(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
preventSubmit: false,
submitSuccess: function (form, event) {
event.preventDefault();
dosubmit(form);
},
submitError: function (form, event, errors) {
event.preventDefault();
}
}); } );https://stackoverflow.com/questions/15617589
复制相似问题