.ajaxform not working inside the validation submitHandler?(.ajaxform 在验证 submitHandler 中不起作用?)
问题描述
我使用 jquery 验证插件在提交前验证表单在 submitHandler 我使用 ajax 请求用 ajax 发布表单在我使用 .ajax 发送请求之前,但现在表单有图像并且很难通过正常的ajax请求序列化文件元素,因此我使用了这个插件http://www.malsup.com/jquery/form/
i use the jquery validation plugin to validate form before submit in submitHandler i use ajax request to post the form with ajax before i used .ajax to send the request but now the form have image and its so hard to serialize the file element through the normal ajax request and because of this i used this plugin http://www.malsup.com/jquery/form/
现在使用插件后,ajax 请求无法正常工作,不知道为什么这是第一个使用普通 ajax 调用的示例
now after using the plugin the ajax request not working at it all don't know why this the first example with the normal ajax call
$(document).ready(function(){
$("#categoryForm").validate({
submitHandler: function() {
$.ajax({
type:'POST',
url: 'actions/add-category.php',
data: $("#categoryForm").serialize(),
success: function(response) {
$('#status').html(response);
}
});
return false;
}
});
});
使用插件后的这个
$(document).ready(function(){
$("#categoryForm").validate({
submitHandler: function() {
$('#categoryForm').ajaxForm(function() {
alert('the form was successfully processed');
});
return false;
}
});
});
第二个不工作
推荐答案
尝试反转函数:
jQuery('#form_id').ajaxForm({
beforeSubmit: function() {
jQuery("#form_id").validate({
rules: {
first_name: "required",
last_name: "required"
},
messages: {
first_name: "Required",
last_name: "Required"
}
});
return jQuery('#form_id').valid();
},
success: function(resp) {
jQuery('#resp').html(resp).fadeIn('fast');
}
});
其中 #resp
是将接收从您的 #form_id
发布的文件生成的 HTML 的 ID
Where #resp
is the ID that will receive the HTML generated from the file your #form_id
posted
这篇关于.ajaxform 在验证 submitHandler 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.ajaxform 在验证 submitHandler 中不起作用?


基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01