jQuery 表单插件在 Send:function() 之前有回调函数吗?



在发送表单数据之前,我需要使用 jquery 验证器插件和自定义验证方法验证我的表单数据。我需要澄清jQuery表单插件是否具有beforeSend 回调函数,如果有,在发送回调函数之前使用的基本要求是什么?

$(function(){
	var obtainFormMeta=function(formId){
		return $(formId).data();
	};
    $('#form-asset-create').ajaxForm({
        beforeSend:function(){
            alert('before send');
            $('#form-asset-create').validate();
        },
        success:function(){
            var options=obtainFormMeta('#form-asset-create');
            //alert('Aww snap! '+JSON.stringify(options));
            alert("when success");
            window.location=options.redirectUrl;
        },
        error:function(){
            alert('Unable to add the asset');
        }
    });
});

试试这个

$(function(){
    var obtainFormMeta=function(formId){
        return $(formId).data();
    };
    $('#form-asset-create').ajaxForm({
        beforeSend:function(){
            alert('before send');
            $('#form-asset-create').validate();
        },
        success:function(){
            var options=obtainFormMeta('#form-asset-create');
            //alert('Aww snap! '+JSON.stringify(options));
            alert("when success");
            window.location=options.redirectUrl;
        },
        error:function(){
            alert('Unable to add the asset');
        }
    });
    $('#form-asset-create').ajaxSubmit();
    // return false to prevent normal browser submit and page navigation 
    return false;
});

最新更新